benibenj / vscode-pythonCpp

A Visual Studio Code Debug Extension for debugging mixed Python and C++ code. The extension starts a Python debug session and attaches the C++ debugger to it. This extension is useful for debugging Python programs that call functions from shared libraries (.so/.dll).
Other
47 stars 7 forks source link

How to config python unittest command "Test: Debug Test at Cursor" and be attached by gdb with Python c++ debugger in launch.json? #17

Closed NiKeYiGuN closed 1 year ago

NiKeYiGuN commented 1 year ago

I'm using python C++ debugger, I want to do mixed-debug with C++ for python unittest function, my configuration is as follows, now ${command:testing.debugAtCursor} can be used in launch.json, it works Debug Test at Cursor is configured in launch.json, but it can't be attached to C++ gdb degugger, but for the Current file it can, I don't celebrate the difference.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Debug Test File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "purpose": ["debug-test"],
            "console": "integratedTerminal",
            "justMyCode": true,
            "env": {
                "PYTHONPATH": "${workspaceFolder}",
            }
        },
        {
            "name": "Python: Debug Test Function",
            "type": "python",
            "request": "launch",
            "program": "${command:testing.debugAtCursor}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "env": {
                "PYTHONPATH": "${workspaceFolder}",
            }
        },
        {
            "name": "Python C++ Test File Debugger",              
            "type": "pythoncpp",
            "request": "launch",
            "pythonLaunchName": "Python: Debug Test File",         
            "cppAttachName": "(gdb) Attach"
        },
        {
            "name": "Python C++ Test Func Debugger",              
            "type": "pythoncpp",
            "request": "launch",
            "pythonLaunchName": "Python: Debug Test Function",         
            "cppAttachName": "(gdb) Attach"
        },
        {
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceFolder}/venv/bin/python",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "additionalSOLibSearchPath": "${workspaceFolder}/build/libmeep",
            "targetArchitecture": "x86_64",
            "logging": { "engineLogging": true, "traceResponse": true
            },
            "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
            ]
        },
    ]
}
NiKeYiGuN commented 1 year ago

"name": "Python C++ Test File Debugger" is working but "name": "Python C++ Test Func Debugger" not. "name": "Python: Debug Test Function" can work alone. Or is there any way to achieve what I want by clicking the green play button to the left of each test method.

benibenj commented 1 year ago

Sadly this is not possible as vscode does not support this for unit tests.