Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Python test debugging falls back to default launch configuration after running custom debug-test configuration once #22530

Copy link
Copy link
Open
@RLThomaz

Description

@RLThomaz
Issue body actions

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:

const codeWorkspaceConfig = getConfiguration('launch');

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.

image

However, the second time it's invoked, the field purpose is empty and some other fields show up:

image

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:

const configs = await getConfigurationsForWorkspace(workspaceFolder);
for (const cfg of configs) {
if (
cfg.name &&
cfg.type === DebuggerTypeName &&
(cfg.request === 'test' ||
(cfg as LaunchRequestArguments).purpose?.includes(DebugPurpose.DebugTest))
) {
// Return the first one.
return cfg as LaunchRequestArguments;
}
}
return undefined;

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.

if (!debugConfig) {
debugConfig = {
name: 'Debug Unit Test',
type: 'python',
request: 'test',
subProcess: true,
};
}

Steps to reproduce:

  1. 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": []
	},
  1. Open any Python project that contains tests to run (or create anything simple using pytest).
  2. Add a breakpoint inside the unit-test.
  3. 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.
  4. Watch as the breakpoint is reached, and continue running the test.
  5. Repeat steps 3 to 5, but now watch the breakpoint being skipped.
  6. 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, and Debug Unit Test, the default launch configuration in VSCode.

image

  1. Observe that the output for Python in the Output panel suggests that both debugging sessions used the custom launch configuration Using 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 (ViewOutput, 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

E5presso

Metadata

Metadata

Assignees

Labels

area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.