Open RLThomaz opened 11 months ago
@paulacamargo25, anyway I can help this ticket getting more traction? I may also be able to provide a PR if I get some extra pointers where to look for a root-cause :)
Also experiencing this behaviour, although I can't even get my launch profile to register on the first launch. It seems to be ignored after the move to debugpy
I've been experiencing similar issues. I've found that I can get vscode to re-read and use the custom launch configuration by editing the launch configuration in the *.code-workspace file. I put a custom environment variable (DUMMY=1) that doesn't do anything in the configuration and I just comment/un-comment it as needed to update the file. Doing this resets something and causes vscode to use my custom launch config. It's frustrating having to do this though when it should just work.
I'm also happy to collaborate on getting this fixed.
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 invokinggetConfiguration
in the code line below:https://github.com/microsoft/vscode-python/blob/eb96141dc8540f2b6838f7fab278a86481575ede/src/client/debugger/extension/configuration/launch.json/launchJsonReader.ts#L15
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 timegetConfiguration
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 inreadDebugConfig
will always be false, thus returningundefined
sincecfg.request === 'test'
and(cfg as LaunchRequestArguments).purpose?.includes(DebugPurpose.DebugTest))
will always befalse
:https://github.com/microsoft/vscode-python/blob/eb96141dc8540f2b6838f7fab278a86481575ede/src/client/testing/common/debugLauncher.ts#L117-L129
Since
readDebugConfig
returnsundefined
, the next code executed (below) will create a defaultdebugConfig
ingetLaunchArgs
. This explains why the second run uses the default launch configuration.https://github.com/microsoft/vscode-python/blob/eb96141dc8540f2b6838f7fab278a86481575ede/src/client/testing/common/debugLauncher.ts#L78-L85
Steps to reproduce:
pytest
).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.Python
in theOutput panel
suggests that both debugging sessions used the custom launch configurationUsing launch configuration in workspace folder
.Diagnostic data
python.languageServer
setting: DefaultOutput for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)``` 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: ""
• 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