Exception inside loop wrongly failing doctest

Lie Ryan lie.1296 at gmail.com
Fri Jun 12 05:45:11 EDT 2009


Lie Ryan wrote:
> Steven D'Aprano wrote:
>> One of my doctests is failing, and I suspect a bug.
>>
>> The test involves matching an exception in a for-loop. Here are two
>> simplified versions of the test, both should pass but only the first does.
>>
> 
> tell me, what's the result of 1/0?

Whooopss.. replied too fast...

This seems to work:

>>> for i in [3, 2, 1, 0]:
...     print (i, 1.0/i)
...
Traceback (most recent call last):
...
ZeroDivisionError: float division

it seems that if the expected result is a traceback, the doc result must
starts with the traceback keyword:

"""
The expected output for an exception must *start* with a traceback
header, which may be either of the following two lines, indented the
same as the first line of the example:

Traceback (most recent call last):
Traceback (innermost last):
"""

(emphasizes added)



More information about the Python-list mailing list