microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.25k stars 1.15k forks source link

PATH for selected Venv not used when pytest test run via Run Test #23467

Closed andrewstevens-infineon closed 1 month ago

andrewstevens-infineon commented 1 month ago

venv_selected Type: Bug

Behaviour

When a pytest test is launched using the "Run Test" Button/Command the environment of the selected virtualenv appears not to be set. This contrasts with the behaviour when "Debug Test" Button/Command is used where the Venv environment is used. This will (for example) break test suites relying on finding executables installed in the virtualenv bin directory on PATH.

Steps to reproduce:

  1. Create small pytest test suite.
  2. print(os.environ) in test.
    
    import os

def test_environ(): print("PATH", os.environ["PATH"])


See attached output captured from run.
[Debug_test_run_output.log](https://github.com/microsoft/vscode-python/files/15416337/Debug_test_run_output.log)
[Run_test_run_output.log](https://github.com/microsoft/vscode-python/files/15416338/Run_test_run_output.log)

<!--
**After** creating the issue on GitHub, you can add screenshots and GIFs of what is happening. Consider tools like https://www.cockos.com/licecap/, https://github.com/phw/peek or https://www.screentogif.com/ for GIF creation.
-->

<!-- **NOTE**: Please do provide logs from Python Output panel. -->
# Diagnostic data

<details>

<summary>Output for <code>Python</code> in the <code>Output</code> panel (<code>View</code>→<code>Output</code>, change the drop-down the upper-right of the <code>Output</code> panel to <code>Python</code>)
</summary>

<p>

N/A


</p>
</details>

Extension version: 2024.6.0
VS Code version: Code 1.89.1 (dc96b837cf6bb4af9cd736aa3af08cf8279f7685, 2024-05-07T05:13:33.891Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Remote OS version: Linux x64 5.15.146.1-microsoft-standard-WSL2

-   Python version (& distribution if applicable, e.g. Anaconda): 3.10.12
-   Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
-   Value of the `python.languageServer` setting: Default

<details>
<summary>User Settings</summary>
<p>

languageServer: "Pylance"

testing • pytestEnabled: true

</p>
</details>

<details>
<summary>Installed Extensions</summary>

|Extension Name|Extension Id|Version|
|---|---|---|
|C/C++|ms-vscode.cpptools|1.20.5|
|C/C++ Extension Pack|ms-vscode.cpptools-extension-pack|1.3.0|
|CMake|twxs.cmake|0.0.17|
|CMake Tools|ms-vscode.cmake-tools|1.17.17|
|JavaScript Debugger|ms-vscode.js-debug|1.89.0|
|Pylance|ms-python.vscode-pylance|2024.5.1|
|Python|ms-python.python|2024.6.0|
|Python Debugger|ms-python.debugpy|2024.6.0|
|Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9|
</details>
<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|12th Gen Intel(R) Core(TM) i7-12800H (20 x 2803)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: enabled_on<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_graphite: disabled_off<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: enabled|
|Load (avg)|undefined|
|Memory (System)|31.64GB (3.06GB free)|
|Process Argv|--crash-reporter-id ec714d14-a794-4eea-900c-f84b7a0f633c|
|Screen Reader|no|
|VM|0%|

|Item|Value|
|---|---|
|Remote|WSL: Ubuntu-22.04|
|OS|Linux x64 5.15.146.1-microsoft-standard-WSL2|
|CPUs|12th Gen Intel(R) Core(TM) i7-12800H (20 x 2803)|
|Memory (System)|15.44GB (9.38GB free)|
|VM|0%|
</details><details>
<summary>A/B Experiments</summary>

vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vscorecescf:30445987 vscod805:30301674 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pythonmypyd1:30879173 pythoncet0:30885854 h48ei257:31000450 pythontbext0:30879054 accentitlementst:30995554 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 chatpanelt:31048053 dsvsc021:30996838 jg8ic977:31013176 pythoncenvptcf:31049071 a69g1124:31046351 pythonprt:31056678 dwnewjupytercf:31046870 26j00206:31048877



</details>

<!-- generated by issue reporter -->
eleanorjboyd commented 1 month ago

Hi I think this is a duplicate of https://github.com/microsoft/vscode-python/issues/23408, please let me know if not and I can reopen- thanks!

andrewstevens-infineon commented 3 weeks ago

It doesn't seem to cover the aspect that inconsistent launch environments between Run test and Debug test (definately not right). I'll add a comment in #23408.