From 38d1254b4ac87fe62444f58f5932a80334faabd7 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sat, 13 Jul 2024 11:03:08 -0700 Subject: [PATCH 1/2] Fix pdb header test --- Lib/test/test_pdb.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 343e15a4edc14c..a54ef62f3bae99 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3389,7 +3389,12 @@ def test_header(self): header = 'Nobody expects... blah, blah, blah' with ExitStack() as resources: resources.enter_context(patch('sys.stdout', stdout)) + # patch pdb.Pdb.set_trace() to avoid entering the debugger resources.enter_context(patch.object(pdb.Pdb, 'set_trace')) + # Because pdb.Pdb.set_trace() is patched, we need to manually + # clear _last_pdb_instance so a new instance with stdout redirected + # could be created when pdb.set_trace() is called. + pdb.Pdb._last_pdb_instance = None pdb.set_trace(header=header) self.assertEqual(stdout.getvalue(), header + '\n') From 0678911f0e9c3acd94ec23cdbbd39b06044ffaa7 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sat, 13 Jul 2024 11:06:24 -0700 Subject: [PATCH 2/2] Change comments --- Lib/test/test_pdb.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index a54ef62f3bae99..f71856d3603d73 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3391,9 +3391,9 @@ def test_header(self): resources.enter_context(patch('sys.stdout', stdout)) # patch pdb.Pdb.set_trace() to avoid entering the debugger resources.enter_context(patch.object(pdb.Pdb, 'set_trace')) - # Because pdb.Pdb.set_trace() is patched, we need to manually - # clear _last_pdb_instance so a new instance with stdout redirected - # could be created when pdb.set_trace() is called. + # We need to manually clear pdb.Pdb._last_pdb_instance so a + # new instance with stdout redirected could be created when + # pdb.set_trace() is called. pdb.Pdb._last_pdb_instance = None pdb.set_trace(header=header) self.assertEqual(stdout.getvalue(), header + '\n')