diff options
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r-- | Lib/test/test_support.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 0e87131cfbe..53e8ae76e6f 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -2,7 +2,6 @@ import sys - class Error(Exception): """Base class for regression test exceptions.""" @@ -22,6 +21,26 @@ class TestSkipped(Error): verbose = 1 # Flag set to 0 by regrtest.py use_resources = None # Flag set to [] by regrtest.py +# _output_comparison controls whether regrtest will try to compare stdout +# with an expected-output file. For straight regrtests, it should. +# The doctest driver should set_output_comparison(0) for the duration, and +# restore the old value when it's done. +# Note that this control is in addition to verbose mode: output will be +# compared if and only if _output_comparison is true and verbose mode is +# not in effect. +_output_comparison = 1 + +def set_output_comparison(newvalue): + global _output_comparison + oldvalue = _output_comparison + _output_comparison = newvalue + return oldvalue + +# regrtest's interface to _output_comparison. +def suppress_output_comparison(): + return not _output_comparison + + def unload(name): try: del sys.modules[name] @@ -156,3 +175,29 @@ def run_unittest(testclass): raise TestFailed("errors occurred in %s.%s" % (testclass.__module__, testclass.__name__)) raise TestFailed(err) + +#======================================================================= +# doctest driver. + +def run_doctest(module, verbosity=None): + """Run doctest on the given module. + + If optional argument verbosity is not specified (or is None), pass + test_support's belief about verbosity on to doctest. Else doctest + sys.argv for -v. + """ + + import doctest + + if verbosity is None: + verbosity = verbose + else: + verbosity = None + + oldvalue = set_output_comparison(0) + try: + f, t = doctest.testmod(module, verbose=verbosity) + if f: + raise TestFailed("%d of %d doctests failed" % (f, t)) + finally: + set_output_comparison(oldvalue) |