Description
Type: Bug
Behaviour
Expected vs. Actual
[Expected] When debugging a test using a custom launch configuration that includes "purpose": [ "debug-test" ]
, I expect subsequent debugging sessions to continue using the same, custom launch configuration. [Actual] However, after debugging a test for the first time, any subsequent test debugging (for any test) will fall back to the default launch configuration, i.e., as if the custom launch configuration was not properly configured.
My own investigation
I have debugged the extension and followed the breadcrumbs when running through the steps to reproduce the issue, as written in the section below. Here are my findings:
When debugging a test, the custom launch configuration is read from a *.code-workspace
file by invoking getConfiguration
in the code line below:
When running the debugger for the first time, the call to getConfiguration
will return the correct launch configuration found in the .code-workspace
file (e.g., the one in the section below). Looking at the variables panel, we can see that the first time getConfiguration
is called, it returns everything correctly.
However, the second time it's invoked, the field purpose
is empty and some other fields show up:
This means that, the following if
branch in readDebugConfig
will always be false, thus returning undefined
since cfg.request === 'test'
and (cfg as LaunchRequestArguments).purpose?.includes(DebugPurpose.DebugTest))
will always be false
:
vscode-python/src/client/testing/common/debugLauncher.ts
Lines 117 to 129 in eb96141
Since readDebugConfig
returns undefined
, the next code executed (below) will create a default debugConfig
in getLaunchArgs
. This explains why the second run uses the default launch configuration.
vscode-python/src/client/testing/common/debugLauncher.ts
Lines 78 to 85 in eb96141
Steps to reproduce:
- Create a custom launch configuration to debug Python tests.
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "internalConsole",
"env": {
"PYTEST_ADDOPTS": "--no-cov"
},
"justMyCode": false,
"autoReload": {
"enable": true
},
},
],
"compounds": []
},
- Open any Python project that contains tests to run (or create anything simple using
pytest
). - Add a breakpoint inside the unit-test.
- Debug the unit-test, either by right-clicking on the "Run button" next to the test, and selecting "Debug" or by clicking the "Debug" button on the "Tests" tab.
- Watch as the breakpoint is reached, and continue running the test.
- Repeat steps 3 to 5, but now watch the breakpoint being skipped.
- Open the
DEBUG CONSOLE
and observe the windows available (see image below), there should be two:Python: Debug Tests
, i.e., the name of our custom configuration, andDebug Unit Test
, the default launch configuration in VSCode.
- Observe that the output for
Python
in theOutput panel
suggests that both debugging sessions used the custom launch configurationUsing launch configuration in workspace folder
.
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.9.18
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Unknown
- Value of the
python.languageServer
setting: Default
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
2023-11-26 09:54:21.654 [info] Using launch configuration in workspace folder.
2023-11-26 09:54:22.632 [info] DAP Server launched with command: /local/home/rlthomaz/REDACTED/Python/farm/bin/python /local/home/rlthomaz/.vscode-server/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/adapter
2023-11-26 09:55:03.308 [info] Using launch configuration in workspace folder.
2023-11-26 09:55:04.145 [info] DAP Server launched with command: /local/home/rlthomaz/REDACTED/Python/farm/bin/python /local/home/rlthomaz/.vscode-server/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/adapter
User Settings
languageServer: "Pylance"
testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
Extension version: 2023.20.0
VS Code version: Code 1.84.2 (Universal) (1a5daa3a0231a0fbba4f14db7ec463cf99d7768e, 2023-11-09T10:52:33.687Z)
OS version: Darwin x64 22.6.0
Modes:
Remote OS version: Linux x64 5.4.259-180.361.amzn2int.x86_64
Remote OS version: Linux x64 5.4.259-180.361.amzn2int.x86_64
Remote OS version: Linux x64 5.4.259-180.361.amzn2int.x86_64