bpo-40372: Make doctest example programs exit with code 1 if any test fails

This commit is contained in:
Andreas Sommer 2020-04-23 10:11:42 +02:00
parent ee40e4b856
commit ea26720a74
2 changed files with 12 additions and 3 deletions

View File

@ -83,7 +83,10 @@ Here's a complete but small example module::
if __name__ == "__main__":
import doctest
doctest.testmod()
import sys
fail, _ = doctest.testmod()
if fail:
sys.exit(1)
If you run :file:`example.py` directly from the command line, :mod:`doctest`
works its magic:
@ -147,9 +150,13 @@ continue to do it) is to end each module :mod:`M` with::
if __name__ == "__main__":
import doctest
doctest.testmod()
import sys
fail, _ = doctest.testmod()
if fail:
sys.exit(1)
:mod:`doctest` then examines docstrings in module :mod:`M`.
:mod:`doctest` then examines docstrings in module :mod:`M`, and the program
exits with an unsuccessful code if any test fails.
Running the module as a script causes the examples in the docstrings to get
executed and verified::

View File

@ -0,0 +1,2 @@
``doctest`` program examples now exit with a non-successful code if any test
fails