So let's say I have the following:
import unittest
class MyTests(unittest.TestCase):
def test001(self):
print 'This is test001'
def test002(self):
print 'This is test002'
if __name__ == '__main__':
unittest.main()
print 'Done'
And the output is:
>> This is test001
>> This is test002
>> ----------------------------------------------------------------------
>> Ran 2 tests in 0.001s
>> OK
And I was wondering why doesn't get to print 'Done' (or anything that comes after)?
Pass exit=False
to the unittest.main()
call (documentation):
unittest.main(exit=False)
Here's what I'm getting on the console:
$ python test.py
This is test001
.This is test002
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
Done
FYI, under the hood unittest's TestProgram.runTests()
calls sys.exit()
if the value of exit
is True
(which is by default):
def runTests(self):
...
if self.exit:
sys.exit(not self.result.wasSuccessful())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With