summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2017-09-22 16:29:42 (GMT)
committerGitHub <noreply@github.com>2017-09-22 16:29:42 (GMT)
commit35425d638c0eeb8377620e016f47df3ae08d7061 (patch)
treea45cb506202bf162807a90d1d1ff81f64965c693 /Lib
parentb1558a0368949714f5765702a8d83a2d163eaacf (diff)
downloadcpython-35425d638c0eeb8377620e016f47df3ae08d7061.zip
cpython-35425d638c0eeb8377620e016f47df3ae08d7061.tar.gz
cpython-35425d638c0eeb8377620e016f47df3ae08d7061.tar.bz2
bpo-31389 Add an optional `header` argument to pdb.set_trace() (#3438)
* Give pdb.set_trace() an optional `header` argument * What's new. * Give pdb.set_trace() an optional `header` argument * What's new.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/pdb.py7
-rw-r--r--Lib/test/test_pdb.py12
2 files changed, 17 insertions, 2 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 97618b0..8dd4ded 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1581,8 +1581,11 @@ def runctx(statement, globals, locals):
def runcall(*args, **kwds):
return Pdb().runcall(*args, **kwds)
-def set_trace():
- Pdb().set_trace(sys._getframe().f_back)
+def set_trace(*, header=None):
+ pdb = Pdb()
+ if header is not None:
+ pdb.message(header)
+ pdb.set_trace(sys._getframe().f_back)
# Post-Mortem interface
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 755d265..71d8203 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -9,9 +9,12 @@ import unittest
import subprocess
import textwrap
+from contextlib import ExitStack
+from io import StringIO
from test import support
# This little helper class is essential for testing pdb under doctest.
from test.test_doctest import _FakeInput
+from unittest.mock import patch
class PdbTestInput(object):
@@ -1107,6 +1110,15 @@ class PdbTestCase(unittest.TestCase):
if save_home is not None:
os.environ['HOME'] = save_home
+ def test_header(self):
+ stdout = StringIO()
+ header = 'Nobody expects... blah, blah, blah'
+ with ExitStack() as resources:
+ resources.enter_context(patch('sys.stdout', stdout))
+ resources.enter_context(patch.object(pdb.Pdb, 'set_trace'))
+ pdb.set_trace(header=header)
+ self.assertEqual(stdout.getvalue(), header + '\n')
+
def tearDown(self):
support.unlink(support.TESTFN)