Wierd Test Failure
Peter Otten
__peter__ at web.de
Fri Jun 20 03:50:19 EDT 2008
J-Burns wrote:
> Hello. Im using doctests to check the functions that ive made. Wat i
> dnt understand is that it gives me a fialure even though the expected
> and got values are the same. Check this out:
>
> **********************************************************************
> File "C:\Python25\Lib\idlelib\idle.pyw", line ?, in
> __main__.Test.test8
> Failed example:
> Test.test8()
> Expected:
> True
> Got:
> True
> **********************************************************************
>
> If both the values are returning True how is it possible for the test
> to fail? :S
Here's one way:
$ cat tmp.py
"""
>>> print " \bTrue"
True
"""
import doctest
doctest.testmod()
$ python tmp.py
**********************************************************************
File "tmp.py", line 2, in __main__
Failed example:
print "True"
Expected:
True
Got:
True
**********************************************************************
1 items had failures:
1 of 1 in __main__
***Test Failed*** 1 failures.
" \bTrue" and "True" look the same but won't pass the equality test
performed by doctest.
As a side note, consider putting your own code in a separate file outside
the python distribution. Otherwise you risk messing up python and producing
more "weird" errors.
Peter
More information about the Python-list
mailing list