S
Steven D'Aprano
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.
As a doctest, this passes:
....
(3, 0.33333333333333331)
(2, 0.5)
(1, 1.0)
However, this fails:
....
(3, 0.33333333333333331)
(2, 0.5)
(1, 1.0)
Traceback (most recent call last):
...
ZeroDivisionError: float division
Attached is a simple test script which runs doctest.testmod(). Both tests
should pass, with no output printing. However, it does this:
$ python doctest_error.py
**********************************************************************
File "doctest_error.py", line 14, in __main__
Failed example:
for x in [3, 2, 1, 0]:
print (x, 1.0/x)
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.5/doctest.py", line 1212, in __run
compileflags, 1) in test.globs
File "<doctest __main__[1]>", line 2, in <module>
print (x, 1.0/x)
ZeroDivisionError: float division
**********************************************************************
1 items had failures:
1 of 2 in __main__
***Test Failed*** 1 failures.
I've tested this in Python 2.4, 2.5 and 2.6 and get the same result for all
three.
Have I missed something, or should I report this as 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.
As a doctest, this passes:
.... print (x, 1.0/x)for x in [3, 2, 1]:
....
(3, 0.33333333333333331)
(2, 0.5)
(1, 1.0)
However, this fails:
.... print (x, 1.0/x)for x in [3, 2, 1, 0]:
....
(3, 0.33333333333333331)
(2, 0.5)
(1, 1.0)
Traceback (most recent call last):
...
ZeroDivisionError: float division
Attached is a simple test script which runs doctest.testmod(). Both tests
should pass, with no output printing. However, it does this:
$ python doctest_error.py
**********************************************************************
File "doctest_error.py", line 14, in __main__
Failed example:
for x in [3, 2, 1, 0]:
print (x, 1.0/x)
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.5/doctest.py", line 1212, in __run
compileflags, 1) in test.globs
File "<doctest __main__[1]>", line 2, in <module>
print (x, 1.0/x)
ZeroDivisionError: float division
**********************************************************************
1 items had failures:
1 of 2 in __main__
***Test Failed*** 1 failures.
I've tested this in Python 2.4, 2.5 and 2.6 and get the same result for all
three.
Have I missed something, or should I report this as a bug?