Repository navigation
Debugging pytest tests causes premature exit upon process.join() #981
Description
Activity
- addedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Mar 18, 2026 SebMoore commented
on Mar 18, 2026 ContributorAuthorMore actionsNot sure if this is an issue with vscode-python-debugger, vscode-python or even vscode-extension-test-runner, but putting it here for now :)
For me it just hangs. Not sure why yet.
Adding this to my launch.json lets me debug the test file as a workaround.
{ "name": "Debug pytest multiproc", "type": "debugpy", "request": "launch", "module": "pytest", "args": ["-s", "${workspaceFolder}/tests/test_multiproc.py"], "console": "integratedTerminal", }I get the following output with your test now:
(base) (.venv312) PS C:\Users\rchiodo\source\repos\pylance-release\testing\single> c:; cd 'c:\Users\rchiodo\source\repos\pylance-release\testing\single'; & 'c:\Users\rchiodo\source\repos\pylance-release\testing\single\.venv312\Scripts\python.exe' 'c:\Users\rchiodo\.vscode-insiders\extensions\ms-python.debugpy-2025.19.2026030601-win32-x64\bundled\libs\debugpy\launcher' '54437' '--' '-m' 'pytest' '-s' 'C:\Users\rchiodo\source\repos\pylance-release\testing\single/tests/test_multiproc.py' =================================================================== test session starts =================================================================== platform win32 -- Python 3.12.10, pytest-9.0.2, pluggy-1.6.0 rootdir: C:\Users\rchiodo\source\repos\pylance-release\testing\single collected 1 item tests\test_multiproc.py before! after! . ==================================================================== 1 passed in 2.54s ====================================================================I am seeing the same issue, and unfortunately the workaround Rich Chiodo (@rchiodo) suggested isn't working for me. I've had to just disable subprocess cleanup for debugging, and tolerate hanging processes. I do notice that the debugger call stack has the spawned processes on the same level as main, which seems to suggest that somewhere in the stack it's getting confused and treating these spawned processes as identical to the top-level (where exiting the process should close out the debug session)
- linked a pull request that will close this issueFix premature pytest debug session exit when multiprocessing child process terminates #1023
on May 6, 2026 I've installed the latest build (2026.7.11311009) with the changes on my VSC, and I'm still seeing the issue. I consolidated down to a minimal working example.
- create library.py
from concurrent.futures import ProcessPoolExecutor, wait as futures_wait def worker_func(): import random import time time_to_sleep = random.randint(5, 10) time.sleep(time_to_sleep) return time_to_sleep def library_function(): print("doing some stuff...") futures = [] with ProcessPoolExecutor(max_workers=8) as pool: for _ in range(16): fut = pool.submit(worker_func) futures.append(fut) done, _ = futures_wait(futures) for d in done: print(f"Done in {d.result()} seconds") print("Done with context manager") print("doing some more stuff...")- create test.py
from library import library_function def test_library(): print("starting test") library_function() print("ending test")- Populate minimal pytest.ini
[pytest] testpaths = . pythonpath = . python_files = test*.py- create minimal 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": "Debug Test", "type": "debugpy", "purpose": ["debug-test"], "request": "launch", "console": "integratedTerminal", "justMyCode": false, "cwd": "${workspaceFolder}", "subProcess": true, }, ] }Expected Behavior: expect to be able to reach all breakpoints
Actual Behavior: the first breakpoints in library are reachable, but the final breakpoint (underlined in yellow), after the context manager shut-down, is never reached.
- linked a pull request that will close this issueStrengthen regression coverage for pytest + multiprocessing child-process debug sessions with integration repro tests #1032
on May 11, 2026
Behaviour
Debugging any pytest test that contains code that creates a child process via
multiprocessing'smp.Process()and then later waits for that process to terminate viaprocess.join()results in the debugger exiting early.Specifically, the debugger terminates immediately after the child process terminates. It seems as though the debugger thinks the primary process has terminated, when in fact it's a child process.
Debugging the exact same code but as a standalone python file (i.e. not a test) doesn't cause this issue.
Steps to reproduce:
Diagnostic data
launch.jsonconfigurationOutput for
Pythonin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython)Output for
Python Debuggerin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython Debugger)debugpy.pydevd.34568.log
debugpy.adapter-19128.log
debugpy.pydevd.31448.log
debugpy.launcher-23484.log
debugpy.server-34568.log
debugger.vscode_5969cc3c-fa33-4f22-b0cd-4285a0e2cfe7.log
debugger.vscode_d64cf1b2-b9f0-47bf-9e42-418f78572c05.log