[issue3722] print followed by exception eats print with doctest

Chris Withers report at bugs.python.org
Fri Aug 29 12:54:13 CEST 2008


New submission from Chris Withers <chris at simplistix.co.uk>:

Here's an example from a python interpreter session:

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> def test():
... print "hello"
... raise Exception()
...
 >>> test()
hello
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "<stdin>", line 3, in test
Exception

Now, turning this into a doctests gives:

"""
>>> def test():
...   print "hello"
...   raise Exception()
...
>>> test()
hello
Traceback (most recent call last):
...
Exception
"""

Which when run gives:

**********************************************************************
File "C:\Projects\doctestbug.py", line 6, in __main__
Failed example:
    test()
Exception raised:
    Traceback (most recent call last):
      File "C:\Python25\lib\doctest.py", line 1212, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__[1]>", line 1, in <module>
        test()
      File "<doctest __main__[0]>", line 3, in test
        raise Exception()
    Exception
**********************************************************************
1 items had failures:
   1 of   2 in __main__
***Test Failed*** 1 failures.

The problem is that the function prints output before raising the
exception. If I take the printed output away, the doctest passes fine.
However, especially with dummy fixtures common in doctests, that printed
output needs to be seen to test that things are happening as they should
prior to the exception being raised.

----------
components: Library (Lib)
messages: 72124
nosy: cjw296
severity: normal
status: open
title: print followed by exception eats print with doctest
versions: Python 2.4, Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3722>
_______________________________________


More information about the Python-bugs-list mailing list