Skip to content

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

Closed

Description

@akukuq

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?

Activity

  1. ghost added
    triage-neededNeeds assignment to the proper sub-team
    on Oct 29, 2020
  2. karthiknadig commented on Oct 29, 2020

    @karthiknadig
    Member

    We have marked this issue as "needs decision" to make sure we have a conversation about your issue. We plan to leave this request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

  3. evilmav commented on Oct 29, 2020

    @evilmav

    Same her: running tests from GUI is broken on a package installed using 'setup.py develop'. Likely related, pylint is also broken, marking same package imports as not found.

  4. ryannk commented on Oct 29, 2020

    @ryannk

    Sorry, I am still fairly new to python. What is the expected way for the target package to be installed locally when running pytest? From the pytest documentation it seems like installing pip install -e is suggested.

  5. eric-mj commented on Oct 29, 2020

    @eric-mj

    Not sure if this is related, but the latest extension (v2020.10.33229234) also breaks my tests. When running via GUI I get "Cannot read property 'testsuites' of null". Running pytest from command line works fine. Downgrading to previous extension restores normal operation of my tests.

  6. karthiknadig commented on Oct 30, 2020

    @karthiknadig
    Member

    @emj1991 That is an unrelated issue. Please file a separate bug.

  7. mrdavidlaing commented on Oct 31, 2020

    @mrdavidlaing

    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.

  8. 21 remaining items

  9. arnaudlimbourg commented on Feb 2, 2021

    @arnaudlimbourg

    Domen Jurkovic (@schperplata) If you can try the latest insiders build, it has a flag to turn off isolation. Please try that and let us know if it works for you. The setting is "python.useIsolation": false. This should be set in the User settings.

    Thank you! I chose weekly insiders, added the setting: "python.useIsolation": false and that fixed it for me!

    fixed it for me too!

  10. akukuq commented on Feb 2, 2021

    @akukuq
    Author

    The insiders build v2021.2.531887795-dev works for me too.

  11. mikofski commented on Feb 23, 2021

    @mikofski

    Thanks for vscode+python! And thanks for your volunteer work on this open source project. ❤️

    I tried the insiders build with the insiders version of python extensions, and turned off isolation, but I believe my editable pip install still was removed from python path when running tests from the GUI. because they still fail with the same message even tho they are discovered and work in debug mode:

    ImportError while loading conftest 'c:\Users\mikm\Projects\pvlib-python\pvlib\tests\conftest.py'.
    pvlib\tests\conftest.py:10: in <module>
        import pvlib
    E   ModuleNotFoundError: No module named 'pvlib'
    Error: TypeError: Cannot read property 'testsuites' of null
    

    I opened #15398 before I found this issue, but I don't know if they're duplicates or not. I apologize for creating redundancy, and I'm happy to close it if it is. Thanks!

  12. falkben commented on Mar 4, 2021

    @falkben

    This error has returned for me on pylint 2.7.2, using the weekly dev extension, and turning off isolation. I'm getting the "no name in module" problem report on my imports for editable installs.

    pylint 2.7.2
    astroid 2.5.1
    Python 3.8.6 | packaged by conda-forge | (default, Oct  7 2020, 18:42:56) 
    [Clang 10.0.1 ]
    
  13. ashrauma commented on Mar 31, 2021

    @ashrauma

    TLDR my test passes collectively but fails when run individually

    In my case there is no '' or cwd in sys.path to begin with when I run an individual test (pyvsc-run-isolated.py). But when I add sys.path.append(os.getcwd()) my tests passes individually.

    Can someone shed some light if this is the same issue or different?

  14. brettcannon commented on Mar 31, 2021

    @brettcannon
    Member

    ashrauma it might be, but without more info it's hard to tell. Please open a new issue and fill out the bug report template.

  15. mikofski commented on Mar 31, 2021

    @mikofski

    RE: my comment above the issue was in pvlib-python, tests was not a package and had a conftest.py file that used imported into tests relatively. Resolved in pvlib/pvlib-python#1204

  16. schperplata commented on Apr 20, 2021

    @schperplata

    What is the status with this issue? Use of a global user setting (python.useIsolation) is quite unfortunate in this scenario - it should be a workspace setting since some other workspace might have a different requirements. ATM, I am the maintainer of a couple of projects that have VSC workspaces and they all have its own venv and are used as packages - what I assume is a correct approach, without any hacks. But yet, we still need to use exact very old extension version since otherwise running (not debugging) does not work. Seems to me like other use cases are covered, but this one is not.

    Domen Jurkovic (@schperplata) for security reasons it needs to not be configurable from a cloned repo

    Brett Cannon (@brettcannon) I must confess I don't quite understand this. Can you please provide a bit more info?

    Bottom line: are we stuck with this old version OR do I have to prepare instructions for everyone that use any of our VSC workspaces, to set theri python.useIsolation? I must be missing something very obvious if I am the only one with this issue!

  17. brettcannon commented on Apr 20, 2021

    @brettcannon
    Member

    Domen Jurkovic (@schperplata) we're waiting on a feature from VS Code which we hope will become available in the next couple of releases/months, at which point we can drop the setting.

  18. ashrauma commented on Apr 21, 2021

    @ashrauma

    TLDR my test passes collectively but fails when run individually

    In my case there is no '' or cwd in sys.path to begin with when I run an individual test (pyvsc-run-isolated.py). But when I add sys.path.append(os.getcwd()) my tests passes individually.

    Can someone shed some light if this is the same issue or different?

    I take my words back. I looked again and indeed the cwd path was there and this script is removing it.

    I am going to use a symlink and modify .pth and .egg-link files to workaround it for now. Hoping this will be fixed in future.

  19. karrtikr commented on May 19, 2021

    @karrtikr

    FYI we're planning to remove isolation script with #16274 so this can be closed.

  20. locked as resolved and limited conversation to collaborators on Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-testingfeature-requestRequest for new features or functionalityimportantIssue identified as high-priorityregressionBug didn't exist in a previous release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions