Paul Manta Paul Manta - 7 months ago 19
Python Question

Tests succeed, still get traceback

I'm using Python's

unittest
library and all the tests succeed, but I still get a traceback and I can't understand how I can fix the problem.

........
----------------------------------------------------------------------
Ran 8 tests in 0.020s

OK

Traceback (most recent call last):
File "C:\Users\Paul\Desktop\bloomfilter\test_bloomfilter.py", line 85, in <module>
unittest.main()
File "C:\Programming\PythonX86\Python27\lib\unittest\main.py", line 95, in __init__
self.runTests()
File "C:\Programming\PythonX86\Python27\lib\unittest\main.py", line 231, in runTests
sys.exit(not self.result.wasSuccessful())
SystemExit: False
>>>

Answer

It appears that you are running in the Python shell, which catches exceptions for you so you can continue debugging. If you had been running from the command line, the line

sys.exit(not self.result.wasSuccessful())

would have exited your program with an exit code of 0, which indicates success (this might be counterintuitive if you're unfamiliar with how programs interact with the shell). Since you're running in the interpreter, however, the exception is caught.

I would suggest that there is nothing wrong with your program or your tests. The unittests framework probably just didn't expect to be run interactively!