所以我想说我有以下内容:
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'
输出是:
>> This is test001
>> This is test002
>> ----------------------------------------------------------------------
>> Ran 2 tests in 0.001s
>> OK
我想知道为什么不打印“完成”(或之后发生的任何事情)?
答案 0 :(得分:12)
将exit=False
传递给unittest.main()
来电(documentation):
unittest.main(exit=False)
这是我在控制台上得到的内容:
$ python test.py
This is test001
.This is test002
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
Done
仅供参考,如果TestProgram.runTests()
的值为sys.exit()
(默认为默认值),则在引擎罩单元测试exit
调用True
下:
def runTests(self):
...
if self.exit:
sys.exit(not self.result.wasSuccessful())