Terry J. Reedy <[email protected]> added the comment:
Temporary output will break all doctests, not just those with exception
traceback. One should fix, disable debug output, and then rerun doctest to make
sure fix did not break anything else.
A function that prints and raises *can* be tested as by separately testing both
output and silencing of expected exception as follows:
>>> def test():
... print("hello")
... raise IndexError()
...
>>> try:
... test()
... raise BaseException()
... except IndexError:
... pass
hello
This passes but will not if function prints anything else or does anything
other than raise that exception (or a subclass thereof). In practice, catching
subclasses should be ok, but if not, the except clause can be expanded to
... except IndexError as msg:
... if type(msg) is not IndexError:
... raise BaseException
I am only leaving this open for a possible doc addition showing something like
the simpler fix above.
----------
assignee: -> docs@python
components: +Documentation -Library (Lib)
nosy: +docs@python
stage: -> needs patch
Added file: http://bugs.python.org/file21065/doctest_solution.py
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue3722>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com