On this page
doctest.DocTestRunner
Prev: doctest.DocTestParser | Up: doctest | Next: doctest.DocTestSuite
Rel: doctest.debug, doctest.debug_src, doctest.DebugRunner, doctest.DocFileSuite
Ref: docs.python.org — doctest.DocTestRunner
Tags: #public #python3 #stdlib #doctest
Import
import doctest
from doctest import DocTestRunner
Signature & Overview
doctest.DocTestRunner(checker=None, verbose=None, optionflags=0)
A class used to run DocTest test cases, and accumulate statistics.
Methods & Attributes
DocTestRunner.merge(self, other)—DocTestRunner.mergemethod/property.DocTestRunner.report_failure(self, out, test, example, got)— Report that the given example failed.DocTestRunner.report_start(self, out, test, example)— Report that the test runner is about to process the given example. (Only displays a message if verbose=True)DocTestRunner.report_success(self, out, test, example, got)— Report that the given example ran successfully. (Only displays a message if verbose=True)DocTestRunner.report_unexpected_exception(self, out, test, example, exc_info)— Report that the given example raised an unexpected exception.DocTestRunner.run(self, test, compileflags=None, out=None, clear_globs=True)— Run the examples intest, and display the results using the writer functionout.DocTestRunner.summarize(self, verbose=None)— Print a summary of all the test cases that have been run by this DocTestRunner, and return a TestResults instance.
Usage
import doctest
test = doctest.DocTestParser().get_doctest(">>> 2 + 2\n4\n", {}, "math", "m.py", 1)
res = doctest.DocTestRunner().run(test)
assert res.failed == 0 and res.attempted == 1
Gotchas
- Pass
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACEfor flexible matching.
REPL Inspect
from doctest import DocTestRunner
help(DocTestRunner)
Linked from
Related notes
- tuts/python3/stdlib_module/doctest/DocTestParser Linked here; links to this page; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTestSuite Linked here; links to this page; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/debug Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/debug_src Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DebugRunner Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocFileSuite Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTest Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/doctest/DocTestFailure shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTestFinder shared tags: #doctest, #stdlib