mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
b1558a0368
commit
35425d638c
5 changed files with 34 additions and 6 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue