Unintended removal of valid "sys.path" entries by isolation script
See original GitHub issueEnvironment data
- VS Code version: 1.45.1
- Extension version (available under the Extensions sidebar): 2020.5.78807
- OS and version: ArchLinux (May)
- Python version: 3.8.2 (ArchLinux)
- Type of virtual environment used: pipenv
- Jedi or Language Server: Language Server
- Value of the
python.languageServer
setting: Microsoft
Expected behaviour
After starting a debug session of a pytest test function, sys.path
should contain all entires which are avialable if you would run pytest ...
from a terminal.
Actual behaviour
The isolation script does not only remove entries from sys.path
which are related to VSCode, it will also remove one additional entry from sys.path
which may break your debug session.
Steps to Reproduce
-
Clone Example Repository
-
Run
pipenv sync --dev
andpipenv run pip install -e src
from the repository root. -
Make sure to execute commands in a pipenv shell.
-
Run
pytest tests/
which should work. -
Open repository in VSCode and use pipenv environment as python interpreter.
-
Debug the example test function, you will recieve
ModuleNotFoundError: No module named 'exampleproject'
.
Workaround 1
-
Remove
del sys.path[0]
from~/.vscode-oss/extensions/ms-python.python-XXXX.X.XXXXX/pythonFiles/pyvsc-run-isolated.py
. -
Debug the example test function, it should work now.
Workaround 2
-
Remove
.env
from repository root. -
Debug the example test function, it should work now.
Explanation of Problem
The tests of the example project uses an editable installation of the exampleproject
package.
If you start a debug session, sys.path
is modified to run the test in an isolated environment.
Unfortunately, not only the vscode related entries are removed, but an additional entry is also modified.
This entry is the path of the editable installation if you use the provided .env
file and will result in failed tests because exampleprojec
is missing in the python path.
If you do not use the .env
file, the debug session might work but (in my case) /usr/lib/python38.zip
is removed/replaced.
This may lead to unexpected behavior of debug sessions.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:9 (2 by maintainers)
Top GitHub Comments
We’ve landed a fix. It will go out in the August release.
Probably the simplest solution is to replace
sys.path[0]
with a known non-existent dirname, rather than removing the entry. I’ll put up a PR.