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"
]
}
]``
I'd try following the instructions from the VS Code Python docs' section on debugging tests, which states:
To customize settings for debugging tests, you can specify
"purpose": ["debug-test"]
in thelaunch.json
file in the.vscode
folder from your workspace. This configuration will be used when you run Test: Debug All Tests, Test: Debug Tests in Current File and Test: Debug Test at Cursor commands.For example, the configuration below in the
launch.json
file disables thejustMyCode
setting for debugging tests:{ "name": "Python: Debug Tests", "type": "debugpy", "request": "launch", "program": "${file}", "purpose": ["debug-test"], "console": "integratedTerminal", "justMyCode": false }
If you have more than one configuration entry with
"purpose": ["debug-test"]
, the first definition will be used since we currently don't support multiple definitions for this request type.
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. Also potentially related: Pytest restart debugger works only with code-workspace files #21365.
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:
{
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
"presentation": {
"hidden": true, // keep original launch order in 'run and debug' tab
}
},
],
"version": "0.2.0"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With