1
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: breakpoints set

As soon as I do "Debug test", the breakpoints in the library code get disabled: disabled breakpoints

rioV8
  • 24,506
  • 3
  • 32
  • 49
Roy Smith
  • 2,039
  • 3
  • 20
  • 27
  • 1
    This is called **Unbound Breakpoint**. Can [this answer](https://stackoverflow.com/a/74565249/18359438) solve your problem? – MingJie-MSFT Mar 16 '23 at 01:41
  • Interesting. If I follow the suggestion there, i.e. try to re-add the breakpoint after starting to debug, I get: "Breakpoint in file excluded by filters. Note: may be excluded because of "justMyCode" option (default == true).Try setting "justMyCode": false in the debug configuration (e.g., launch.json)." – Roy Smith Mar 16 '23 at 03:30

1 Answers1

0

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.

Roy Smith
  • 2,039
  • 3
  • 20
  • 27