all Python 3doctestexception
doctest.DocTestFailure
exceptions
Raised by DebugRunner when an example's output does not match the expectation. It carries test, example and the actual output got.
Syntax
except doctest.DocTestFailure as e: e.test, e.example, e.got
The regular DocTestRunner and testmod() never raise it — they write a report. The exception exists so you can stop at the first mismatch and examine it in code or a debugger: e.example.want is the expectation, e.got the actual output, both ending in a newline.
Examples
import doctest
test = doctest.DocTestParser().get_doctest(">>> 0.1 + 0.2\n0.3\n", {}, "t", None, 0)
try:
doctest.DebugRunner().run(test)
except doctest.DocTestFailure as e:
print(repr(e.example.want), repr(e.got)) # → '0.3\n' '0.30000000000000004\n'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy