Skip to content

Commit 0ba3b4e

Browse files
committed
Address comments
1 parent fb65bb1 commit 0ba3b4e

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

Lib/test/test_pdb.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,28 +3666,6 @@ def test_print_stack_entry_uses_dynamic_line_prefix(self):
36663666
# Check if the custom prefix appeared in the output
36673667
self.assertIn('CUSTOM_PREFIX> ', stdout.getvalue())
36683668

3669-
def test_exec_in_closure_result_uses_pdb_stdout(self):
3670-
"""
3671-
Expression results executed via _exec_in_closure() should be written
3672-
to the debugger output stream (pdb stdout), not to sys.stdout.
3673-
"""
3674-
pdb_out = io.StringIO()
3675-
sys_out = io.StringIO()
3676-
3677-
p = pdb.Pdb(nosigint=True, readrc=False, stdout=pdb_out)
3678-
3679-
with redirect_stdout(sys_out):
3680-
self.assertTrue(p._exec_in_closure('(lambda: 123)()', {}, {}))
3681-
self.assertTrue(p._exec_in_closure('sum(i for i in (1, 2, 3))', {}, {}))
3682-
3683-
pdb_lines = [line.strip() for line in pdb_out.getvalue().splitlines()]
3684-
sys_lines = [line.strip() for line in sys_out.getvalue().splitlines()]
3685-
3686-
self.assertIn('123', pdb_lines)
3687-
self.assertIn('6', pdb_lines)
3688-
self.assertNotIn('123', sys_lines)
3689-
self.assertNotIn('6', sys_lines)
3690-
36913669
def test_find_function_found_with_encoding_cookie(self):
36923670
self._assert_find_function(
36933671
"""\

Lib/test/test_remote_pdb.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,34 @@ def test_multi_line_commands(self):
14411441
self.assertIn("Function returned: 42", stdout)
14421442
self.assertEqual(process.returncode, 0)
14431443

1444+
def test_exec_in_closure_result_uses_pdb_stdout(self):
1445+
"""
1446+
Expression results executed via _exec_in_closure() should be written
1447+
to the debugger output stream (pdb stdout), not to sys.stdout.
1448+
"""
1449+
self._create_script()
1450+
process, client_file = self._connect_and_get_client_file()
1451+
1452+
with kill_on_error(process):
1453+
self._read_until_prompt(client_file)
1454+
1455+
self._send_command(client_file, "(lambda: 123)()")
1456+
messages = self._read_until_prompt(client_file)
1457+
result_msg = "".join(msg.get("message", "") for msg in messages)
1458+
self.assertIn("123", result_msg)
1459+
1460+
self._send_command(client_file, "sum(i for i in (1, 2, 3))")
1461+
messages = self._read_until_prompt(client_file)
1462+
result_msg = "".join(msg.get("message", "") for msg in messages)
1463+
self.assertIn("6", result_msg)
1464+
1465+
self._send_command(client_file, "c")
1466+
stdout, _ = process.communicate(timeout=SHORT_TIMEOUT)
1467+
1468+
self.assertNotIn("\n123\n", stdout)
1469+
self.assertNotIn("\n6\n", stdout)
1470+
self.assertEqual(process.returncode, 0)
1471+
14441472

14451473
def _supports_remote_attaching():
14461474
PROCESS_VM_READV_SUPPORTED = False

0 commit comments

Comments
 (0)