Repository navigation
Pytest: Debug test uses incomplete python executable path #25452
Description
Type: Bug
Behaviour
When attempting to debug a pytest test using Debug Test from the VS Code Testing panel in an anaconda environment, I get the following error:
"Failed to spawn launcher: [Errno 13] Permission denied: '/Users/username/anaconda3/envs/my_conda_env'"
The reason I get that error is that Code attempts to launch the debug server using only the environment's root path rather than than the path to the python executable within that environment. I.e., it calls /Users/username/anaconda3/envs/my_conda_env instead of /Users/username/anaconda3/envs/my_conda_env/bin/python to launch the debugger. And because a directory is not executable, I get the permission denied error.
I used to be able to debug tests no problem. I'm not sure if something in my setup changed or if something in plugin changed. I've googled and played with settings and tried different conda environments. I've tried setting a different "python" option in the debug-test launch configuration (I get errors if I set a bad path for that option, but when it's a good path, it seems to be ignored). I've deleted and recreated the conda environment. I've even deleted and reinstalled VS Code.
I can run tests within VS Code or from the command line without debugging and hit no errors. I can also debug a single python file with the very same launch configuration that is meant for debugging tests (even including the "purpose" option set to ["debug-test"]) by launching the debugger directly. The problem only occurs when launching a debug session through the Debug Test option on the Testing panel.
Steps to reproduce:
- create a conda environment and install pytest
- create a new project workspace
- create a python file in the workspace with a simple function calling, e.g.,
print("Hello, word") - select the conda environment created in step 1 as python environment for the project
- create a
testsfolder in the workspace with a single pytest that calls the test function - go to the Testing panel in VS Code and setup pytest testing
- after test discovery completes, click the "debug test" button next to the test nameResult: VS Code pops up an alert reporting the "Permission denied" error
For more detail, you can set up a debug configuration for the tests in the launch.json file using the exact configuration provided in the Python Extension documentation at: [https://code.visualstudio.com/docs/python/testing#_debug-tests], with the "console" option set to "integratedTerminal" -- there, you can see the command Code is using to attempt to start the debug server.
Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2025-09-09 12:36:56.122 [info] > ~/anaconda3/bin/conda run -p ~/anaconda3/envs/my_conda_env --no-capture-output python ~/.vscode/extensions/ms-python.python-2025.12.0-darwin-arm64/python_files/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2025.12.0-darwin-arm64/python_files/printEnvVariables.py
2025-09-09 12:36:56.122 [info] shell: bash
2025-09-09 12:36:57.166 [info] arg: --rootdir already exists in args, not adding.
2025-09-09 12:36:57.166 [info] Attempting to use temp directory for test ids file, file name: test-ids-c79eea80e8781efba974.txt
2025-09-09 12:36:57.166 [info] Environment variables set for pytest execution: PYTHONPATH=/Users/username/.vscode/extensions/ms-python.python-2025.12.0-darwin-arm64/python_files, TEST_RUN_PIPE=/var/folders/7b/j6zzgg8j1v3d83xn_msb1xnw0000gn/T/python-test-results-2a0dee1c2989b48f6149, RUN_TEST_IDS_PIPE=/var/folders/7b/j6zzgg8j1v3d83xn_msb1xnw0000gn/T/test-ids-c79eea80e8781efba974.txt
2025-09-09 12:36:57.166 [info] Running DEBUG pytest with arguments: --rootdir=/Users/username/Source/test_project,--capture=no for workspace /Users/username/Source/test_project
2025-09-09 12:36:57.167 [info] Using configuration in launch.json
Output for integrated terminal panel
(my_conda_env) username@host project_folder % cd /Users/username/Source/project_folder ; /usr/bin/en
v /Users/username/anaconda3/envs/my_conda_env /Users/username/.vscode/extensions/ms-python.debugpy-2025.10.0-d
arwin-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher 50578 -- /Users/username/.vscode/extensions
/ms-python.python-2025.12.0-darwin-arm64/python_files/vscode_pytest/run_pytest_script.py --rootdir=/Users
/username/Source/project_folder --capture=no
env: /Users/username/anaconda3/envs/my_conda_env: Permission denied
Extension version: 2025.12.0
VS Code version: Code 1.103.2 (6f17636121051a53c88d3e605c491d22af2ba755, 2025-08-20T16:45:34.255Z)
OS version: Darwin arm64 24.6.0
Modes:
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.11
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServersetting: Default
User Settings
condaPath: "~/anaconda3/bin/conda"
languageServer: "Pylance"
testing
• pytestArgs: "--no-cov"
• pytestEnabled: true
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| cmake-tools | ms- | 1.21.36 |
| copilot | Git | 1.364.0 |
| copilot-chat | Git | 0.30.3 |
| cpptools | ms- | 1.26.3 |
| cpptools-extension-pack | ms- | 1.3.1 |
| cpptools-themes | ms- | 2.0.0 |
| datawrangler | ms- | 1.22.0 |
| debugpy | ms- | 2025.10.0 |
| hexeditor | ms- | 1.11.1 |
| intellicode-api-usage-examples | Vis | 0.2.9 |
| js-debug | ms- | 1.102.0 |
| js-debug-companion | ms- | 1.1.3 |
| jupyter | ms- | 2025.7.0 |
| jupyter-keymap | ms- | 1.1.2 |
| jupyter-renderers | ms- | 1.3.0 |
| makefile-tools | ms- | 0.12.17 |
| python | ms- | 2025.12.0 |
| ruff | cha | 2025.24.0 |
| vscode-js-profile-table | ms- | 1.0.10 |
| vscode-jupyter-cell-tags | ms- | 0.1.9 |
| vscode-jupyter-slideshow | ms- | 0.1.6 |
| vscode-pylance | ms- | 2025.7.1 |
| vscode-python-envs | ms- | 1.2.0 |
| vscodeintellicode | Vis | 1.3.2 |
System Info
| Item | Value |
|---|---|
| CPUs | Apple M1 Max (10 x 2400) |
| GPU Status | 2d_canvas: enabled 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: enabled_on trees_in_viz: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | 6, 15, 15 |
| Memory (System) | 64.00GB (6.59GB free) |
| Process Argv | --crash-reporter-id 7daef490-db9b-4617-abaa-559a02220920 |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368:30146709
pythonvspyt551:31249599
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
996jf627:31283433
pythonrdcb7:31342333
usemplatestapi:31297334
6518g693:31334701
aj953862:31281341
nesew2to5:31336538
agentclaude:31374413
4f60g487:31327383
nes-set-on:31340697
6abeh943:31336334
envsactivate1:31353494
0927b901:31350571
45650338:31358607
0cj2b977:31352657
gaj49834:31362110
pylancealldocsf:31379511
gemagent1:31368469
cloudbuttont:31379625
retryenabled:31370050
3efgi100_wstrepl:31382709
trigger-command-fix:31379601
Activity
couteau commentedon Sep 11, 2025
Update: I found a workaround -- setting the "pythonPath" entry in the launch configuration for test debugging to the full python path I want to use makes everything work. According to the launch configuration schema and documentation, "pythonPath" is not a legal entry, but looking at the code (specifically,
resolveAndUpdatePythonPathinsrc/client/debugger/extension/configuration/resolvers/base.ts), it definitely uses the "pythonPath" entry (and not the "python" entry, which IS legal) to set the "debugAdapterPython" and "debugLauncherPython" entries that appear to be the ones actually used to launch the debugger.If "pythonPath" is not set in the launch configuration, it is apparently set using
InterpreterService.getActiveInterpreter, but I have not been able to figure out where or why that is going wrong.eleanorjboyd commentedon Sep 11, 2025
Hi! Can you update to the newest version of the python extension and python environments extension. I made a fix for this which should be out on stable. Thanks!
couteau commentedon Sep 13, 2025
Hi - thank you. It's now 99% working. There is one peculiarity left:
When I first start-up Code, the first time I try to debug a test with "console" set to "integratedTerminal" in the launch configuration, Code creates a new terminal labeled "Debug". But it does not switch to the conda environment in the Debug terminal before starting to run the test. As a result, I get errors on some import statements (specifically, those that are in a non-default location that is added to the PYTHONPATH when the environment is activated). As soon as the test terminates with that import error and falls back to the prompt in the terminal window, the terminal activates the correct conda environment. After that, debugging tests works correctly, because it reuses the same terminal with the now correctly activated environment. If I close that terminal, then I get this same error the next time I try to debug a test. And if I remove the "console": "integratedTerminal" option, everything works from the get-go.
Even stranger, it seems to use the correct path to the python executable for the conda environment, even though the conda environment has not been activated. I can see that in the console and also by putting a breakpoint on the first faulty import statement and looking at sys.executable.
So in the terminal on the first test run, the prompt shows that "(base)" is the active, but the python executable it's using to launch the debugger is the one from "my_test_env". After the test crashes, the terminal executes "conda activate my_test_env", and everything works going forward.
Other than this, everything is good.