Pytest - Run test from test explorer fail with uppercase test folder name
See original GitHub issueEnvironment data
- VS Code version: 1.35.1
- Extension version (available under the Extensions sidebar): 2019.6.22090
- OS and version: Windows 10 Home Edition
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.8
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): global python 3.6.8
- Relevant/affected Python packages and their versions: pytest 4.6.3
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): Jedi
Expected behaviour
Test file could be run from test explorer in activity bar.
Actual behaviour
Test file could not run from test explorer in activity bar.
CodeLens adornments disappear from the test file.
Steps to reproduce:
- enable pytest from D:\projectRoot.vscode\setting.json as following:
{
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"Test"
]
}
- project folder structure is as following:
D:\projectRoot\
.vscode\
SRC\
src.py
Test\
__init__.py
test_src.py
- Run Test file from test explorer in activity bar
Logs
Python Test Log say that:
============================= 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Pytest not able to discover tests in VS code - Stack Overflow
Following the creation of the project, i run the Python: Discover Tests command, which then creates the .vscode directory with the following ...
Read more >Testing Python in Visual Studio Code
unittestArgs : Looks for any Python ( . py ) file with "test" in the name in the top-level project folder. All test...
Read more >Pytest - a beginner guide. - Numpy Ninja
First we have to create a directory and then, create a test file in the directory. Here, Test is a package created under...
Read more >Robot Framework with Selenium and Python: All You Need to ...
Robot framework offers an extensible keyword driven approach to Selenium testing. Go from beginner to advanced with our comprehensive Robot ...
Read more >Test Terraform modules in Azure using Terratest
For each unit test case, we first run terraform init and target the test fixture folder ( ./test/fixtures/storage-account-name/ ).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 https://github.com/pytest-dev/pytest/issues/2761#issue-256094577 changes the way they deal with paths on case-insensitive systems.
Basically, the workarounds I found was: