0

Today I wrote a test and no matter what I did I couldn't pass the test.

then I discovered that I get SystemExit: False even without any test cases :

>>> ================================ RESTART ================================
>>> import unittest
>>> unittest.main()

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Traceback (most recent call last):
  File "<pyshell#123>", line 1, in <module>
    unittest.main()
  File "C:\Python27x64\Lib\unittest\main.py", line 95, in __init__
    self.runTests()
  File "C:\Python27x64\Lib\unittest\main.py", line 231, in runTests
    sys.exit(not self.result.wasSuccessful())
SystemExit: False

Is this behavior normal? also:

>>> class aTest(unittest.TestCase):
    def test_123(self):
        self.assertEqual(2, 1+1)


>>> unittest.main()
.
----------------------------------------------------------------------
Ran 1 test in 0.011s

OK

Traceback (most recent call last):
  File "<pyshell#133>", line 1, in <module>
    unittest.main()
  File "C:\Python27x64\Lib\unittest\main.py", line 95, in __init__
    self.runTests()
  File "C:\Python27x64\Lib\unittest\main.py", line 231, in runTests
    sys.exit(not self.result.wasSuccessful())
SystemExit: False
thkang
  • 11,215
  • 14
  • 67
  • 83

1 Answers1

2

You are trying to run the unit test in an interactive shell, which is probably not what the unittest module was meant to be used for. In particular, when the unittest finishes, it explicitly tries to exit "the program", but as you run it from an interactive shell, this fails.

Did you try putting the code in a file and running it (I tried your code from a .py file, and it seems to work without raising errors).

Caspar
  • 81
  • 2