Skip to content

gh-132912: Kill the process on error in test_remote_pdb #132920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Lib/test/test_remote_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
from pdb import _PdbServer, _PdbClient


@contextmanager
def kill_on_error(proc):
"""Context manager killing the subprocess if a Python exception is raised."""
with proc:
try:
yield proc
except:
proc.kill()
raise


class MockSocketFile:
"""Mock socket file for testing _PdbServer without actual socket connections."""

Expand Down Expand Up @@ -360,7 +371,7 @@ def test_connect_and_basic_commands(self):
self._create_script()
process, client_file = self._connect_and_get_client_file()

with process:
with kill_on_error(process):
# We should receive initial data from the debugger
data = client_file.readline()
initial_data = json.loads(data.decode())
Expand Down Expand Up @@ -413,7 +424,7 @@ def test_breakpoints(self):
"""Test setting and hitting breakpoints."""
self._create_script()
process, client_file = self._connect_and_get_client_file()
with process:
with kill_on_error(process):
# Skip initial messages until we get to the prompt
self._read_until_prompt(client_file)

Expand Down Expand Up @@ -489,8 +500,7 @@ def bar():
self._create_script(script=script)
process, client_file = self._connect_and_get_client_file()

with process:

with kill_on_error(process):
# Skip initial messages until we get to the prompt
self._read_until_prompt(client_file)

Expand Down Expand Up @@ -520,7 +530,7 @@ def test_handle_eof(self):
self._create_script()
process, client_file = self._connect_and_get_client_file()

with process:
with kill_on_error(process):
# Skip initial messages until we get to the prompt
self._read_until_prompt(client_file)

Expand Down Expand Up @@ -568,7 +578,7 @@ def run_test():
self._create_script(script=script)
process, client_file = self._connect_and_get_client_file()

with process:
with kill_on_error(process):
# First message should be an error about protocol version mismatch
data = client_file.readline()
message = json.loads(data.decode())
Expand All @@ -591,7 +601,7 @@ def test_help_system(self):
self._create_script()
process, client_file = self._connect_and_get_client_file()

with process:
with kill_on_error(process):
# Skip initial messages until we get to the prompt
self._read_until_prompt(client_file)

Expand Down Expand Up @@ -630,7 +640,7 @@ def test_multi_line_commands(self):
self._create_script()
process, client_file = self._connect_and_get_client_file()

with process:
with kill_on_error(process):
# Skip initial messages until we get to the prompt
self._read_until_prompt(client_file)

Expand Down
Loading