diff options
author | Jim Fulton <jim@zope.com> | 2004-08-09 11:34:47 (GMT) |
---|---|---|
committer | Jim Fulton <jim@zope.com> | 2004-08-09 11:34:47 (GMT) |
commit | 356fd19c31882e35b34027b4c12fa8922e74e3ca (patch) | |
tree | 42bee78e3da802e8fc0743fe4db6750327df8dba /Lib/doctest.py | |
parent | 9dc19c2515637344bf871870114669252bd72773 (diff) | |
download | cpython-356fd19c31882e35b34027b4c12fa8922e74e3ca.zip cpython-356fd19c31882e35b34027b4c12fa8922e74e3ca.tar.gz cpython-356fd19c31882e35b34027b4c12fa8922e74e3ca.tar.bz2 |
Added support for pdb.set_trace.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 21cbc32..5dd0bae 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -187,10 +187,12 @@ __all__ = [ import __future__ import sys, traceback, inspect, linecache, os, re, types -import unittest, difflib, tempfile +import unittest, difflib, pdb, tempfile import warnings from StringIO import StringIO +real_pdb_set_trace = pdb.set_trace + # Option constants. DONT_ACCEPT_TRUE_FOR_1 = 1 << 0 DONT_ACCEPT_BLANKLINE = 1 << 1 @@ -1251,15 +1253,28 @@ class DocTestRunner: """ if compileflags is None: compileflags = _extract_future_flags(test.globs) + if out is None: out = sys.stdout.write saveout = sys.stdout + # Note that don't save away the previous pdb.set_trace. Rather, + # we safe pdb.set_trace on import (see import section above). + # We then call and restore that original cersion. We do it this + # way to make this feature testable. If we kept and called the + # previous version, we'd end up restoring the original stdout, + # which is not what we want. + def set_trace(): + sys.stdout = saveout + real_pdb_set_trace() + try: sys.stdout = self._fakeout + pdb.set_trace = set_trace return self.__run(test, compileflags, out) finally: sys.stdout = saveout + pdb.set_trace = real_pdb_set_trace if clear_globs: test.globs.clear() |