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."""
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())
"""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)
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)
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)
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())
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)
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)