-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing with pytest always issues a file not found error #6548
Comments
This seems to happen due to inline |
Can you please paste the directory structure and content, like @luabud did. Will help to reproduce the issue. |
@luabud I can confirm that if test directory contains an For eg. |
Not sure if it the same bug or not. Getting
|
i have the exactly same issue as following when the file is actually in the folder, "d:\workspace\nebula_data\folderabc\tests\test_china_stock_basics.py"
seems the pytest incorrectly calculated the path of file by ignoring its parently folder, but it wired that actually other test files in the same folder works well. |
fwiw, I was seeing the issue #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). |
I have met similar problem with @luabud . And the werid thing is that it works fine when I start tests by clicking the button from the side panel. |
I've also ran into the above issue. Log output:
File Structure:
Settings:
|
As has already been noted, if there is a pytest.ini file in the test root then we run into this problem. I was able to verify that this is not a problem if the file is in any other directory, even a sub-directory of the test root. I also found that this bug is impacted by test discovery. The following two cases indicate that test execution is tied to test discovery:
Running with "--cache-clear" did not make a difference. I also found that running a single test fails because it tries to use a path relative to the test root rather than CWD (the workspace root). This is basically the same problem. Finally, I was able to reproduce the problem at revision b4aa1f0, which predates the recent refactoring of the XUnit parser (#7263/#7265 for #6990). |
The key problem is that, with pytest.ini in the test root, pytest returns filenames (for both discovery and execution) that are relative to the test root. In all other cases they are relative to the workspace root. However, the extension code makes the assumption that the relative filenames are always relative to the workspace root. In the case of a failed test we do a lookup using the absolute filename (see This will be resolved if we do one of the following:
I prefer (3). In the case of running individual tests, that will be resolved if we do one of the following:
(Note that "fileToRun" is not modified during execution, at least for pytest.) I prefer (1). |
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. |
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?The text was updated successfully, but these errors were encountered: