Repository navigation
Cannot import "tests" module from my own workspace #4566
Description
With the latest version of the extension (2019.2.5416), there appears to be a set of "data science" tests under pythonFiles\tests that are causing a path conflict when we try to run our own integration "tests" using PyTest.
Running the following VS Code launch config:
"name": "Integration tests (windows)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"module": "pytest",
"args": [
"--html=integrationtests_windows/report.html",
"tests/integrationtests"
],
},
....results in the following error:
ImportError while loading conftest 'D:\git\vam\tests\integrationtests\conftest.py'.
tests\integrationtests\conftest.py:15: in <module>
from tests.utils.database_utils import (
E ModuleNotFoundError: No module named 'tests.utils'
If I add in an import tests statement before the failing import, and then set a breakpoint, I can see in the Variables/Locals panel that the tests module is actually loaded from C:\Users\Ian Claridge\.vscode\extensions\ms-python.python-2019.2.5416\pythonFiles\tests instead of D:\git\vam\tests. D:\git\vam is the working directory - the folder loaded in VSCode.
Environment data
- VS Code version: 1.31.1
- Extension version (available under the Extensions sidebar): 2019.2.5416
- OS and version: Windows 10 Enterprise 1803 build 17134.590
- Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32)
- Type of virtual environment used venv
- Relevant/affected Python packages and their versions: n/a
Comparison with a previous version of the extension shows that the pythonFiles\tests module is new, which is why this issue started appearing today.
Expected behaviour
My integration tests run.
Actual behaviour
I get a ModuleNotFoundError exception.
Steps to reproduce:
- See above description.
Logs
$ cd "d:\git\vam" ; env "PYTHONPATH=." "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" "d:\git\vam\venv\Scripts\python.exe" "c:\Users\Ian Claridge\.vscode\extensions\ms-python.python-2019.2.5416\pythonFiles\ptvsd_launcher.py" --default --client --host localhost --port 52340 -m pytest --html=integrationtests_windows/report.html tests/integrationtests
sys.path: ['D:\\git\\vam\\tests\\integrationtests', '', 'c:\\Users\\Ian Claridge\\.vscode\\extensions\\ms-python.python-2019.2.5416\\pythonFiles', 'D:\\git\\vam', 'D:\\git\\vam\\venv\\Scripts\\python36.zip', 'D:\\Tools\\Python36\\DLLs', 'D:\\Tools\\Python36\\lib', 'D:\\Tools\\Python36', 'D:\\git\\vam\\venv', 'D:\\git\\vam\\venv\\lib\\site-packages', 'D:\\git\\vam\\venv\\lib\\site-packages\\win32', 'D:\\git\\vam\\venv\\lib\\site-packages\\win32\\lib', 'D:\\git\\vam\\venv\\lib\\site-packages\\Pythonwin']
tests module: <module 'tests' from 'c:\\Users\\Ian Claridge\\.vscode\\extensions\\ms-python.python-2019.2.5416\\pythonFiles\\tests\\__init__.py'>
ImportError while loading conftest 'D:\git\vam\tests\integrationtests\conftest.py'.
tests\integrationtests\conftest.py:21: in <module>
from tests.utils.database_utils import (
E ModuleNotFoundError: No module named 'tests.utils'
Activity
DonJayamanne commentedon Feb 27, 2019
Does it work with you delete the
testsdirectory from the extension?Cladge commentedon Feb 27, 2019
Hi Don. Yes, it does work when I delete (or rename) the
testsdirectory from the extension. I guessed that would work, but deleting or renaming folders that belong to the extension does not seem ideal!Is there a problem with the order of paths in
sys.path? As you can see from the attached log output in the issue description, thec:\\Users\\Ian Claridge\\.vscode\\extensions\\ms-python.python-2019.2.5416\\pythonFilespath appears before my workspace path (D:\\git\\vam).DonJayamanne commentedon Feb 27, 2019
Thats, fine, its just a bug in our extension, just wanted to ensure it works before we re-publish another version.
Hang in there, we'll publish a new version with this fix.
Bump version for hot fix #4566
Cladge commentedon Feb 27, 2019
Thanks, Don. Much appreciated! 👍