[Tutor] Unittest traceback

Kent Johnson kent37 at tds.net
Fri Apr 4 13:36:16 CEST 2008


Oleg Oltar wrote:
> Hi! 
> 
> I am trying to use unittest in python first time. But have a strange 
> traceback each time I run my sample tests.

How are you running the test? My guess is that you are running it in an 
IDE or something that shows the normal system exit exception.

Calling sys.exit() raises the SystemExit exception with a result code. 
Normally this is not shown by the runner.

In Python False == 0 so your program is exiting normally with a code of 
0 (no error). It is probably the program runner that is showing the 
traceback.

Try running the program from the command line.

Kent

> Can you please explain why I have it. No info about it in the doc. 
> e.g. the code is
> 
> import unittest
> import squaren
> 
> class TestCases(unittest.TestCase):
>     def setUp(self):
>         pass
> 
>     def testsmall(self):
>         self.assertEqual(True, True)
> 
> 
> 
> if __name__ == '__main__':
>     unittest.main()
> 
> And the traceback is 
> 
> ----------------------------------------------------------------------
> Ran 1 test in 0.000s
> 
> OK
> Traceback (most recent call last):
>   File "/tmp/py359hJx", line 14, in <module>
>     unittest.main()
>   File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
>     self.runTests()
>   File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
>     sys.exit(not result.wasSuccessful())
> SystemExit: False


More information about the Tutor mailing list