Skip to content

Cannot import "tests" module from my own workspace #4566

@Cladge

Description

@Cladge

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:

  1. 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'

Metadata

Metadata

Assignees

Labels

area-testingbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions