question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`pyvsc-run-isolated.py` removes pip "editable" installations from `sys.path`, breaks pytest

See original GitHub issue

In #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:closed
  • Created 3 years ago
  • Reactions:58
  • Comments:38 (9 by maintainers)

github_iconTop GitHub Comments

13reactions
akukuqcommented, Nov 10, 2020

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

8reactions
mrdavidlaingcommented, Oct 31, 2020

For me; pytest and pylint were finding finding modules using the PYTHONPATH=. 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Good Integration Practices — pytest documentation
If you don't use an editable install and are relying on the fact that Python by default puts the current directory in sys.path...
Read more >
PATH issue with pytest 'ImportError: No module named ...
I'm not sure why py.test does not add the current directory in the PYTHONPATH itself, but here's a workaround (to be executed from...
Read more >
Specification of editable installation - Discussions on Python.org
This focuses on the long-term specification since the desicussion on solutions before it is covered in Pip 19.1 and installing in editable ......
Read more >
pipenv Documentation - Read the Docs
The recommended way to install pipenv on most platforms is to install ... a user installation to prevent breaking any system-wide packages.
Read more >
Running setuptools commands - Python Packaging Authority
replacement for python setup.py install pip install --editable . ... They can be simply downloaded and added to sys.path directly, or they can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found