Python Glossary Русский

all Python 3doctestterm

doctest.DebugRunner

debugging

A DocTestRunner variant that raises an exception on the first failure instead of writing a report, for post-mortem debugging.

Syntax

doctest.DebugRunner(checker=None, verbose=None, optionflags=0).run(test)

Wrong output raises DocTestFailure and an exception inside an example raises UnexpectedException; the remaining examples do not run. The namespace is not cleared after a failure, so variables are visible in the debugger. It is what the debug() method of DocTestSuite test cases uses.

Examples

import doctest
test = doctest.DocTestParser().get_doctest(">>> x = 1\n>>> x + 1\n3\n>>> x\n1\n", {}, "t", None, 0)
try:
    doctest.DebugRunner(verbose=False).run(test)
except doctest.DocTestFailure as e:
    print(e.example.source.strip(), "->", e.got.strip())  # → x + 1 -> 2
    print(e.test.globs["x"])  # → 1 — пространство имён не очищено

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy