Skip to content

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

Closed

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'

Activity

  1. ghost added
    triage-neededNeeds assignment to the proper sub-team
    on Feb 27, 2019
  2. DonJayamanne commented on Feb 27, 2019

    @DonJayamanne

    Does it work with you delete the tests directory from the extension?

  3. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Feb 27, 2019
  4. Cladge commented on Feb 27, 2019

    @Cladge
    Author

    Hi Don. Yes, it does work when I delete (or rename) the tests directory 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, the c:\\Users\\Ian Claridge\\.vscode\\extensions\\ms-python.python-2019.2.5416\\pythonFiles path appears before my workspace path (D:\\git\\vam).

  5. DonJayamanne commented on Feb 27, 2019

    @DonJayamanne

    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.

  6. added a commit that references this issue on Feb 27, 2019
    4d8ca68
  7. Cladge commented on Feb 27, 2019

    @Cladge
    Author

    Thanks, Don. Much appreciated! 👍

  8. locked as resolved and limited conversation to collaborators on Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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