Skip to content

When debugging pytest test case, debugger detatches when subprocess.run invokes python #993

@SamuelBailey

Description

@SamuelBailey

I have tests with pytest, where, if I try to use subprocess.run to invoke another instance of the python interpreter during my test, and then I try to step through that test with a debugger, the python debugger detaches.

If I connect the debugger to the file itself, instead of running on the test case, it is able to step over every line of code, and does not detach. However if I use the "Testing" menu on the left hand side of VSCode to run test cases with a debugger (or selecting the icon next to the test), the debugger will detatch after the line subprocess.run:

Image

Below is a snippet that reproduces the issue.

import subprocess


def test_subprocess():
    stdout = subprocess.run(
        ["python", "-c", "print('Hello')"],
        text=True,
        capture_output=True,
    ).stdout
    assert stdout == "Hello\n"


if __name__ == "__main__":
    test_subprocess()

My ms-python.debugpy version is 2025.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage-neededNeeds assignment to the proper sub-team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions