`pyvsc-run-isolated.py` removes pip "editable" installations from `sys.path`, breaks pytest
See original GitHub issueIn #14014, pythonFiles/pyvsc-run-isolated.py
script has been modified to remove all occurrences of cwd
or ''
from sys.path
. Previously, this script just blindly replaced (and before that it removed) sys.path[0]
. The purpose of #14014 was to handle situations in which cwd
is not the first item in sys.path
.
The unintended side effect of #14014 arises when a package residing in cwd
is installed with pip install -e .
(as an editable install). Such installation causes cwd
to be added at the end of sys.path
. In these situations, cwd
exists twice in sys.path
: first as ''
and second as cwd
. Removing both occurrences breaks everything that needs to import the package installed as editable.
In my case what is broken is running pytest
tests from the GUI. Side note: why is pytest run using the isolate script?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:58
- Comments:38 (9 by maintainers)
@brettcannon , if I understand you correctly the motivation of the isolate script is to make tests/linters function even if they would not work when run from the terminal emulator, e.g. due to name clashes between files in workspace root and stdlib modules. If this is so, I would like to offer my view on this matter for your consideration:
Before coming to VSCode I have been a PyCharm user (many of my colleagues still are). For me, the most important advantage of using VSCode over PyCharm is that VSCode puts the user in charge of far more aspects of workspace configuration than PyCharm does. Moreover, VSCode is configured through text files and allows the user to configure tests/linters/whatnot using the standard configuration files of the respective programs. These files can than be committed to repository, reused by other users (even using other IDEs) and (very importantly) in CI context. This has huge value when it comes to educating users how to use all these tools without VSCode. VSCode encouraged me to learn things and made me a better programmer, PyCharm prevents users from learning.
To illustrate how important this can be I can say the following: It is very common for my colleagues who exclusively use PyCharm to have problems with correct configuration of their projects, to the point that some of the software they write works only when run from within PyCharm! I recall that one piece of software had installation instructions that started with “1. Install PyCharm”.
For this reason I feel that IDEs should not try to fix what users have broken. This makes them ignorant of how projects should be organized. In my opinion testing and linting should be run directly in user’s environment.
For me;
pytest
andpylint
were finding finding modules using thePYTHONPATH=.
setting in my${workspaceFolder}/.env
file. (as suggested here)The behaviour introduced in #14014 that removes $(cwd) from
sys.path
breaks this setting; causing both to fail.