You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pytest - Run test from test explorer fail with uppercase test folder name #6410
============================= test session starts =============================
platform win32 -- Python 3.6.8, pytest-4.6.3, py-1.5.2, pluggy-0.12.0
rootdir: d:\projectRoot
collected 0 items / 1 errors
=================================== ERRORS ====================================
______________________ ERROR collecting test/test_src.py ______________________
ImportError while importing test module 'd:\projectRoot\test\test_src.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
ModuleNotFoundError: No module named 'test.test_src'
...
Additional Information
All the setting work for the vscode-python for previous release (2019.5.18875).
When I change the folder name containing the test file from Test to test, with python.testing.pytestArgs setting in setting.json to ["test"], test file could be run from test explorer. However, codeLens adornments still disappear.
It seems for the current release, vscode-python change the uppercase letter for folder name to lowercase before they import the test module. This change to letter case cause the problem.
Reacted by Philippe MacKay, Jon Strutz and Christian Pütz
changed the title [-]Run test from test explorer fail with lower case test folder name[/-][+]Run test from test explorer fail with uppercase test folder name[/+]on Jul 2, 2019
I am not getting similar errors, but I can confirm the tests in directory with uppercase test folder name are not being run.
Similar #6347 (comment)
Please refer to #6303 for code lenses issue. It says renaming first letter of the first dir in the workspace path to lowercase solved the issue.
changed the title [-]Run test from test explorer fail with uppercase test folder name[/-][+]Pytest - Run test from test explorer fail with uppercase test folder name[/+]on Jul 3, 2019
I have a very similar issue. After updating to 2019.6.22090, every capital letter in the test module's path will be turned to lowercase when displayed in the test explorer. A quick fix could be to avoid any capital letter in any source file and folder names, but that would go against our naming convention.
When using "Run All Tests" or "Debug All Tests" buttons in the test explorer, I see in the Python Test Log output window that tests are executed (and whether they pass or not), and the status bar icon reflects the correct result. However, pass/fail results are not reported in the test explorer.
However, when I try to run or debug tests using the green "Play" arrow next to the lowercase test module name, I get a test collection error. Interestingly, when I look at the log message, it correctly capitalizes paths outside of the current workspace, but not paths inside the current workspace. For example, a test module in a workspace located in C:\Sources\ProjectName would have the following path: C:\Sources\ProjectName\TestModules\test_SomeModule.py, but when called from the test explorer, the log displays that PyTest tries to import c:\Sources\ProjectName\testmodules\test_somemodule.py
The test explorer also returns an "all lowercase" version of the file path (from "c:" to ".py") when trying to access the code from the test explorer view. I can't have any code lens on tests if there is a capital letter anywhere in the test module's full path.
Reverting to 2019.5.18875 fixes all these issues.
VS Code version: 1.36.1
Extension version (available under the Extensions sidebar): 2019.6.22090
OS and version: Windows 10 Pro 64-bit, version 1809, build 17763.557
Python version : Python 3.7.3
Type of virtual environment used : N/A (also affects venv and virtualenv)
Relevant/affected Python packages and their versions: pytest 5.0.1
Jedi or Language Server?: Jedi (both are affected)
After thorough investigation, I realized this happens with pytest version 5.0.0 and upper, and the extension's TestCollector (in pythonFiles/testing_tools/adapter/pytest/_discovery.py) which applies os.path.normcase on every path.
According to pytest's change log https://docs.pytest.org/en/latest/changelog.html#id15, bugfix pytest-dev/pytest#2761 (comment) changes the way they deal with paths on case-insensitive systems.
Basically, the workarounds I found was:
Use most recent version of pytest and VSCode Python extension version 2019.5.18875 --> everything works as it should.
OR
Use most recent version of both VSCode Python extension and pytest, but modify the file ~/.vscode/extensions/ms-python.python-2019.X.XXXXX/pythonFiles/testing_tools/adapter/pytest/_discovery.py line 64: add an exception on windows such that NORMCASE maps to os.path.normpath instead of os.path.normcase. It solves all my problems, but I suspect it could create a bunch of problems in other situations 😏.
Activity
[-]Run test from test explorer fail with lower case test folder name[/-][+]Run test from test explorer fail with uppercase test folder name[/+]karrtikr commentedon Jul 3, 2019
I am not getting similar errors, but I can confirm the tests in directory with uppercase test folder name are not being run.
Similar #6347 (comment)
Please refer to #6303 for code lenses issue. It says renaming first letter of the first dir in the workspace path to lowercase solved the issue.
[-]Run test from test explorer fail with uppercase test folder name[/-][+]Pytest - Run test from test explorer fail with uppercase test folder name[/+]PhilMacKay commentedon Jul 9, 2019
I have a very similar issue. After updating to 2019.6.22090, every capital letter in the test module's path will be turned to lowercase when displayed in the test explorer. A quick fix could be to avoid any capital letter in any source file and folder names, but that would go against our naming convention.
When using "Run All Tests" or "Debug All Tests" buttons in the test explorer, I see in the Python Test Log output window that tests are executed (and whether they pass or not), and the status bar icon reflects the correct result. However, pass/fail results are not reported in the test explorer.
However, when I try to run or debug tests using the green "Play" arrow next to the lowercase test module name, I get a test collection error. Interestingly, when I look at the log message, it correctly capitalizes paths outside of the current workspace, but not paths inside the current workspace. For example, a test module in a workspace located in C:\Sources\ProjectName would have the following path: C:\Sources\ProjectName\TestModules\test_SomeModule.py, but when called from the test explorer, the log displays that PyTest tries to import c:\Sources\ProjectName\testmodules\test_somemodule.py
The test explorer also returns an "all lowercase" version of the file path (from "c:" to ".py") when trying to access the code from the test explorer view. I can't have any code lens on tests if there is a capital letter anywhere in the test module's full path.
Reverting to 2019.5.18875 fixes all these issues.
AnneTheAgile commentedon Jul 9, 2019
Is this windows only ?
On mac I do not think I have this issue.
angelo-peronio commentedon Jul 11, 2019
I observe the same behaviour reported by PhilMacKay above #6410 (comment)
PhilMacKay commentedon Aug 7, 2019
After thorough investigation, I realized this happens with pytest version 5.0.0 and upper, and the extension's TestCollector (in pythonFiles/testing_tools/adapter/pytest/_discovery.py) which applies os.path.normcase on every path.
According to pytest's change log https://docs.pytest.org/en/latest/changelog.html#id15, bugfix pytest-dev/pytest#2761 (comment) changes the way they deal with paths on case-insensitive systems.
Basically, the workarounds I found was:
OR
OR
ericsnowcurrently commentedon Aug 13, 2019
This should be resolved now due to #6781 and #6877. Those changes are already in the insiders build of the extension and will be part of the September release.
ericsnowcurrently commentedon Aug 14, 2019
Philippe MacKay (@PhilMacKay) indicated that this is resolved. See #6820 (comment)