Skip to content

Virtual environment is not fully activated when running tests in non-debug mode #22630

Open

Description

Type: Bug

Behaviour

Expected vs. Actual

Expected: When I run discovered pytests in non-debug mode via the "testing" tab, it behaves as though I ran pytest with the virtual environment configured for the workspace activated.

Actual: I have a particular test which uses subprocess.run to spawn another script which executes with the Python interpreter using a shebang (#!/usr/bin/env python3). When I run this test in my shell with the Python virtual environment active, the shebang executable resolves to the binary for the active environment, the desired behaviour. However, when I run the same test using the "testing" feature in VSCode, the executable is resolved to the system Python binary and the test fails as a consequence.

It is notable that this does not occur when I run the test in debug mode, there it works properly.

Steps to reproduce:

See the sample repository with steps to reproduce in the README: https://github.com/KyleRAnderson/vscode-python-bug-22630.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.6
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

User Settings


languageServer: "Pylance"

testing
• cwd: "<placeholder>"
• pytestArgs: "<placeholder>"
• pytestEnabled: true

Extension version: 2023.22.0
VS Code version: Code 1.85.0 (af28b32d7e553898b2a91af498b1fb666fdebe0c, 2023-12-06T20:48:09.019Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Remote OS version: Linux x64 5.15.133.1-microsoft-standard-WSL2
Remote OS version: Linux x64 5.15.133.1-microsoft-standard-WSL2
Connection to 'wsl+ubuntu' could not be established

System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i7-13700 (24 x 2112)
GPU Status 2d_canvas: enabled
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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.76GB (2.03GB free)
Process Argv --crash-reporter-id aac21859-ebaf-495b-a1ef-a5146502f3a6
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu
OS Linux x64 5.15.133.1-microsoft-standard-WSL2
CPUs 13th Gen Intel(R) Core(TM) i7-13700 (24 x 2111)
Memory (System) 7.64GB (3.55GB free)
VM 0%
Item Value
Remote WSL: Ubuntu
OS Linux x64 5.15.133.1-microsoft-standard-WSL2
CPUs 13th Gen Intel(R) Core(TM) i7-13700 (24 x 2111)
Memory (System) 7.64GB (3.55GB free)
VM 0%

Connection to 'wsl+ubuntu' could not be established

A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
py29gd2263:30899288
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
2e4cg342:30602488
89544117:30613380
showlangstatbar:30737416
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
welcomedialog:30910333
pythonnosmt12:30797651
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
dsvsc013:30795093
dsvsc014:30804076
dsvsc015:30845448
pythontestfixt:30902429
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
2e7ec940:30885897
pythontbext0:30879054
accentitlementst:30887150
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
aa_t_chat:30882232
dsvsc019:30917259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions