-
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
Pytest doesn't run in venv on Remote workstation and so fails #24841
Comments
@strubbly Can you share a test that we can use to repro this? which variables are you relying on? May I ask why you are relying on activated env variables? https://docs.python.org/3/library/venv.html#how-venvs-work
|
This is an example of a test that demonstrates the issue:
The
If I run pytest in the integrated terminal then it succeeds. But if I run it in the test explorer, I get this output
and the test fails. |
I can see that it is not recommended to rely on environment variables being set in the activation script when using the venv. However, we are where we are and nearly everything (including the integrated terminal) does indeed correctly activate with the activate script before using the venv. And a lot of our infrastructure relies on that. So far the test explorer is the only thing we can't get to work. |
@strubbly is it standard one that is generated when using |
The |
@strubbly another question, would it work if you update the |
No that wouldn't really work because the environment variables need to be set per virtual environment and we can have more than one per user. The environment variables control library versions (and other things) and need to match the things installed in the venv. |
As a temporary workaround I thought I would try adding one version of the possible environment variables into my |
I wondered why the correct environment is used when running under debug. At first I thought it might be because I was running the debug sessions with a |
Type: Bug
Behaviour
Some of my pytest tests rely on environment variables set during venv activation. They work when run in the integrated terminal (because the venv is activated) and under debug (that is set to run in a Debug terminal and that too gets the venv activated). But they don't run in the Test Explorer - they fail because the environment variables are not set correctly.
My settings include
I have tried various permutations of
but none of those seem to make any difference.
I am aware that similar bugs have been reported before and that fixes have been released but this is happening with the latest VS code and extension versions. The test explorer used to work correctly with these settings and much earlier versions - specifically Python v2022.8.1
Steps to reproduce:
Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)The third line of the output includes a listing of environment variables but these do not include the ones that would have been set had the
activation taken place. I have redacted the detail.
Extension version: 2025.0.0
VS Code version: Code 1.97.2 (e54c774e0add60467559eb0d1e229c6452cf8447, 2025-02-12T23:20:35.343Z)
OS version: Darwin arm64 24.3.0
Modes:
Remote OS version: Linux x64 4.18.0-553.32.1.el8_10.x86_64
python.languageServer
setting: DefaultUser Settings
Installed Extensions
System Info
canvas_oop_rasterization: enabled_on
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
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: