Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Cladge opened this issue Feb 27, 2019 · 4 comments
Closed

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

Cladge opened this issue Feb 27, 2019 · 4 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@Cladge
Copy link

Cladge commented Feb 27, 2019

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'
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Feb 27, 2019
@DonJayamanne
Copy link

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

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Feb 27, 2019
@Cladge
Copy link
Author

Cladge commented Feb 27, 2019

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).

@DonJayamanne
Copy link

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.

DonJayamanne added a commit that referenced this issue Feb 27, 2019
@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug area-testing unplanned labels Feb 27, 2019
@DonJayamanne DonJayamanne self-assigned this Feb 27, 2019
@Cladge
Copy link
Author

Cladge commented Feb 27, 2019

Thanks, Don. Much appreciated! 👍

@lock lock bot locked as resolved and limited conversation to collaborators Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants