-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Python Tests fails to load PYTHONPATH #21642
Comments
Thank you for your issue report. We are looking into this now! In the meantime, you are likely on the new testing rewrite and this is why you saw a change in behavior since we just moved to this experiment to a larger group of people receiving it. You can opt out of the rewrite as I get this fix in by setting this in your user settings: |
Hello quick question, is this behavior a regression, ie have you had this work in the past and it no longer does? Secondly, can you check to see if you can see this in your logs |
Had the same issue and adding |
As far as I know this is not a regression; I have not had this work before. I'm not sure how to check my logs for The only settings I have related to testing is: However I just checked today and reran the test and everything somehow works now. I can no longer reproduce the error. I'm pretty confused as to what happened, everything even works when I remove the |
Yea... now VSCode seems to inherit the PYTHONPATH variable that I exported in .bashrc even with an empty settings file. So, I guess I don't have any issues relating to this anymore, although I'm not really sure what happened between when I opened the issue and now. |
I had the same problem originally reported here, except that it was solved by adding |
Thank you, for your responses. Can someone else check to see if they also only see this issue on the rewrite? You can opt out of the rewrite as I get this fix in by setting this in your user settings: You can confirm you have the rewrite enabled by setting Let me know if the rewrite fixes your issue. Thanks! |
I'm pretty sure this happens to me as well, but toggling the |
@andypexai I will investigate further. When you say setting the .env file helps the debugger are you saying that this setup works when you debug but not any other way? |
Looks like I have this issue too, when using Double checked |
Another case here. I described my situation extensively in #21872. |
Hey @eleanorjboyd, this issue might need further attention. @yygrechka, you can help us out by closing this issue if the problem no longer exists, or adding more information. |
@eleanorjboyd sorry for not answering sooner. Not long after, I stopped having my specific problem. |
@eleanorjboyd I'm fine to close out the issue if you are. |
Great thank you! |
@eleanorjboyd I still see this issue if I don't opt out of the new test adapter experiment, and we keep having to opt out team members if they've been included. Is there any more info I can provide? |
Hi @woodyza, what version of vscode and the python extension are you on? Can you also describe your project setup more so I can look to replicating it? |
I actually inadvertently found a solution to my issue while I was setting up a simple repo to reproduce. Basically it's a monorepo using a src layout, with multiple apps and some shared packages all in one repo. Something like:
Previously we were using What does work however is using pytests pythonpath argument to do the same thing, eg in [tool.pytest.ini_options]
pythonpath = [
"src",
] FWIW my vscode info is:
And the python extension is at |
found the issue- seems we are not referencing the user-defined env file as part of the environment when configuring the sub-process for the test run. I will add it now but this will require a PR. In the meantime hopefully, your workaround can suffice and I will close this issue when the fix is merged. Thanks |
Thanks @eleanorjboyd! |
Is anyone able to verify if this is fixed? If not I can have a team member do so before our next stable release. Thanks! |
Using the |
Type: Bug
Behaviour
Expected vs. Actual
I have this in my settings file: "terminal.integrated.inheritEnv": true
This seems to have correctly imported my PYTHONPATH that I set in my .bashrc for the purposes of development. (i.e. code completion, jump to definition etc...) all work as expected. However when I write a test file, the test functionality in VSCode fails. I'm able workaround the failure by manually including the path of my custom module via sys.path.append, however, this should not be necessary.
My workspace:
bug_test
-- classA.py
-- tests
---- test_A.py
classA:
test_A:
The expected behavior is for the test to pass.
The actual behavior is:
Workaround:
Adding this line in test_A.py : sys.path.append('/home/grechkay/yyg_projects')
fixes the issue and the test passes.
However, this has already been added to the PYTHONPATH in the bashrc file, which is recognized by all of the other VSCode functionality except for the tests.
Steps to reproduce:
Diagnostic data
python.languageServer
setting: DefaultOutput for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)User Settings
Extension version: 2023.12.0
VS Code version: Code 1.80.1 (74f6148eb9ea00507ec113ec51c489d6ffb4b771, 2023-07-12T17:22:25.257Z)
OS version: Linux x64 5.15.0-76-generic
Modes:
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: