When debugging unit tests through the GUI, I don’t know how to configure VS Code to step inside third-party code.
Note: I use a workspace.
Edit: Currently as a workaround I can use this configuration from "Run and Debug tab" where I have to specify which test I want to run:
"configurations": [
{
"name": "Debug specific test",
"type": "python",
"module": "pytest",
"request": "launch",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
"args": [
"explorer/test/test_projects_controller.py::TestProjectsController::test_get_metadata"
]
}
]``
2
Answers
This is a limitation in current VSCode version: VSCode only uses
launch.json
file to configure pytest debugging options, it ignores the workspace launch section.It is planned to be fixed soon: https://github.com/microsoft/vscode-python/issues/21249
As a workaround, we can duplicate the workspace launch section in a
.vscode/launch.json
file, ex:I’d try following the instructions from the VS Code Python docs’ section on debugging tests, which states:
Note: I’ve also seen older configs floating around that use
"request": "test"
instead of"purpose": ["debug-test"]
(Ex. this), so you can try that if"purpose": ["debug-test"]
doesn’t work for you.There also seems to be a
"debugStdLib": true
property you can use if you want to step into standard library things (source).There’s an open issue ticket where this is apparently not working for version 2023.8.0 of the Python extension (#21249), but it will be fixed in later versions.