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

testlauncher.py overwrites sys.path #11363

Closed
ghsme opened this issue Apr 23, 2020 · 6 comments
Closed

testlauncher.py overwrites sys.path #11363

ghsme opened this issue Apr 23, 2020 · 6 comments
Labels
area-testing bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster needs PR Ready to be worked on

Comments

@ghsme
Copy link

ghsme commented Apr 23, 2020

Environment data

  • VS Code version: 1.44.2
  • Extension version (available under the Extensions sidebar): 2020.4.74986
  • OS and version: Win 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8
  • Type of virtual environment used: venv

Expected behaviour

sys.path is not modified

Actual behaviour

line 26: sys.path[0] = os.getcwd()
overwrites top entry in the sys.path during unit test debugging (pytest in this case). This leads to errors to find modules that were available on that path. It is not obvious why this behavior as there are no comments, but it seems the intention was to insert cwd at the top of sys.path

Steps to reproduce:

  1. Place a module to be tested in a directory that is not workspace directory or any other standard module search path
  2. Add .env to the project and include PYTHONPATH with the directory of the module being tested like ./src (PYTHONPATH=./src)
  3. Write unit test with pytest. Make sure unit test module imports module being tested
  4. Place breakpoint in the unit test.
  5. Observe breakpoint never reached and debug console shows error pointing to the import statement

Workaround

Edit testLauncher.py and comment out the offending line or replace with sys.path.insert(0, os.getcwd())

@ghsme ghsme added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Apr 23, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 23, 2020
@ancillaryCode
Copy link

This broke my test debugging this morning. The workaround fixes it.

@karrtikr karrtikr removed their assignment Apr 23, 2020
@karrtikr
Copy link

Thanks for identifying the fix, we can the confirm that it's bug.

@RobertDeRose
Copy link

I also have this issue and the workaround did work for me as well!

@fsackur
Copy link

fsackur commented May 14, 2020

For n00bs like me working in a dev container, the default location of testlauncher.py is one of ~/.vscode-server-insiders/extensions/ms-python.python-2020.5.78807/pythonFiles/testlauncher.py or ~/.vscode-server/extensions/ms-python.python-2020.5.78807/pythonFiles/testlauncher.py (substitute the version you have installed)

@github-actions github-actions bot removed the needs PR label Aug 9, 2022
@karrtikr karrtikr added the needs PR Ready to be worked on label Aug 9, 2022
@eleanorjboyd eleanorjboyd added ghc-osd info-needed Issue requires more information from poster labels Sep 19, 2023
@eleanorjboyd
Copy link
Member

Hello! We have just finished our testing rewrite and are beginning the roll out to users. If you are able, it would be very helpful to know if your issue still exists on the rewrite! To try it yourself, add this setting to your users settings.json "python.experiments.optInto": ["pythonTestAdapter"].

You can confirm you have the rewrite enabled by setting "python.analysis.logLevel": "Trace", in your user settings then check for Experiment 'pythonTestAdapter' is active in your python logs.

Let me know if the rewrite fixes your issue. Thanks!

@github-actions
Copy link

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

Happy Coding!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2023
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 info-needed Issue requires more information from poster needs PR Ready to be worked on
Projects
None yet
Development

No branches or pull requests

7 participants