Skip to content

Commit 6c542b7

Browse files
committed
Edward's latest checkins somehow managed to wipe out my previous latest
checkins. Reapplying the latter changes.
1 parent a1ef611 commit 6c542b7

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎Lib/doctest.py‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,27 +1259,30 @@ def run(self, test, compileflags=None, out=None, clear_globs=True):
12591259
if compileflags is None:
12601260
compileflags = _extract_future_flags(test.globs)
12611261

1262+
save_stdout = sys.stdout
12621263
if out is None:
1263-
out = sys.stdout.write
1264-
saveout = sys.stdout
1265-
1266-
# Note that don't save away the previous pdb.set_trace. Rather,
1267-
# we safe pdb.set_trace on import (see import section above).
1268-
# We then call and restore that original cersion. We do it this
1269-
# way to make this feature testable. If we kept and called the
1270-
# previous version, we'd end up restoring the original stdout,
1271-
# which is not what we want.
1264+
out = save_stdout.write
1265+
sys.stdout = self._fakeout
1266+
1267+
# Patch pdb.set_trace to restore sys.stdout, so that interactive
1268+
# debugging output is visible (not still redirected to self._fakeout).
1269+
# Note that we run "the real" pdb.set_trace (captured at doctest
1270+
# import time) in our replacement. Because the current run() may
1271+
# run another doctest (and so on), the current pdb.set_trace may be
1272+
# our set_trace function, which changes sys.stdout. If we called
1273+
# a chain of those, we wouldn't be left with the save_stdout
1274+
# *this* run() invocation wants.
12721275
def set_trace():
1273-
sys.stdout = saveout
1276+
sys.stdout = save_stdout
12741277
real_pdb_set_trace()
12751278

1279+
save_set_trace = pdb.set_trace
1280+
pdb.set_trace = set_trace
12761281
try:
1277-
sys.stdout = self._fakeout
1278-
pdb.set_trace = set_trace
12791282
return self.__run(test, compileflags, out)
12801283
finally:
1281-
sys.stdout = saveout
1282-
pdb.set_trace = real_pdb_set_trace
1284+
sys.stdout = save_stdout
1285+
pdb.set_trace = save_set_trace
12831286
if clear_globs:
12841287
test.globs.clear()
12851288

‎Lib/test/test_doctest.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ def test_pdb_set_trace():
10441044
... >>> calls_set_trace()
10451045
... '''
10461046
>>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0)
1047-
10481047
>>> fake_stdin = tempfile.TemporaryFile(mode='w+')
10491048
>>> fake_stdin.write('\n'.join([
10501049
... 'up', # up out of pdb.set_trace

0 commit comments

Comments
 (0)