visual-studio-codedebuggingpytest

In VS Code, how can I disable justMyCode when running pytest in "Testing" tab


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.

enter image description here


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"
        ]
    }
]``

Solution

  • 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"
    }