vscode-python: Testing with pytest always issues a file not found error
Whenever I run the tests, I always getting this strange error:
Detail: Unable to read file (Error: File not found
I really don’t have a
c
file in my project. But where is it coming from?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (6 by maintainers)
Commits related to this issue
- Force the pytest root dir to always be the workspace root. (#7803) (for #6548) — committed to microsoft/vscode-python by ericsnowcurrently 5 years ago
Not sure if it the same bug or not. Getting
File not found
on Mac OS for pytest when click on shadedRun Test
above the test. The file and the test obviously exist. Error is below.@luabud I can confirm that if test directory contains an
pytest.ini
, and file path for the files in the test directory are being incorrectly calculated while running tests.For eg. Expected path:
c:\Users\luabud\Apps\vscode\tests\two\test_d.py
Actual path:c:\Users\luabud\Apps\vscode\two\test_d.py
I’m getting a similar error:
Environment data
Expected behaviour
no “file not found” errors being displayed in the output channel when running tests
Actual behaviour
“file not found” error is displayed in the output channel. In the case below, for some reason the “tests” folder is being ignored in the file path:
Steps to reproduce:
Open a folder with tests following this structure:
Have at least one of the tests methods fail
Make sure you have a pytest.ini file in the tests folder (in this case I only had
[pytest] addopts = -s -v
in it)Reload the window and run all tests. Watch the following error appear:
Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)It turns out this is the defined behavior for pytest. It will walk up the directory tree, starting at the given directory/file, and set the first ancestor directory with a pytest.ini file as the root. That is exactly what everyone is seeing. The problem is that the extension isn’t coping well with this behavior. It’s going to take some cleverness to get this right.
fwiw, I was seeing the issue https://github.com/microsoft/vscode-python/issues/6990 but then i downgraded to pytest 5.01 and that issue went away. but i still have this issue (file not found on all tests i execute).