【发布时间】:2019-04-10 20:38:37
【问题描述】:
在test_module.py 中,我定义了TestCase 的一个子类,由几个测试方法组成。
import unittest
class abc(unittest.TestCase):
def test1():
...
def test2():
...
我可以通过任一方式将测试方法作为测试用例运行
python3 -m unittest test_module.py
或添加到test_module.py
if __name__ == "__main__":
unittest.main()
然后
python3 test_module.py
在第二种方式中,unittest.main() 在内部创建一个 TestProgram 的实例,它调用 self.runTests(),它创建一个 TextTestRunner 的实例并调用 TextTestRunner.run(),它运行并在 test_module.py 中报告所有测试结果。 Meaning of unittest.main() in Python unittest module.
在第一种方式中,python3 -m unittest test_module.py 后面的内部是否也发生了同样的事情?
【问题讨论】: