I find using doctest.testmod(raise_on_error=True)
will cause an exception to be raised when a test fails, which causes the script exits with a non-zero code.
Optional argument
raise_on_error
defaults to false. If true, an exception is raised upon the first failure or unexpected exception in an example. This allows failures to be post-mortem debugged. Default behavior is to continue running examples.