MacOS Monterey
Python 3.9.13
VS Code 1.76.2
pytest==7.2.0
I'm running out of a virtualenv. When I debug one of my unit tests and try to step into a library function, it doesn't step in, it just runs to completion. Explicitly setting breakpoints in the library code has no effect. I have justMyCode set to false in launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
}
]
}
Per Set breakpoint in imported python module in vs code, I tried adding site-packages to my workspace, but that didn't make any difference.
I can see the breakpoints set in the library code:
As soon as I do "Debug test", the breakpoints in the library code get disabled:
MingJie-MSFT got me pointed in sort-of the right direction, but How to disable "just my code" setting in VSCode debugger? is really what I needed. Using either of these in my launch.json gets things working (although I will confess to not fully understanding the details):
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"justMyCode": false
},
]
}
or
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
},
{
"name": "Debug Unit Test",
"type": "python",
"request": "test",
"justMyCode": false,
}
]
}
The first one is what https://code.visualstudio.com/docs/python/testing#_debug-tests recommends, so I'll go with that. And having site-packages added to my workspace turned out to be immaterial.
PS, I just saw the comment in How to disable "just my code" setting in VSCode debugger?: "request": "test" is deprecated use "purpose" instead.
Also, https://github.com/microsoft/vscode-python/issues/14388 and https://github.com/microsoft/vscode-python/issues/17644 are related to this.