我在一个模块ops_tests.py
中有多个测试类。
class TestExecuteProc(unittest.TestCase):
def test(self):
<commands>
class TestSetupJobs(unittest.TestCase):
def test(self):
<commands>
现在我只想测试第二节课,所以我在main
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSetupJobs)
unittest.TextTestRunner.run(suite)
然而,它仍然运行两个测试。选择要测试的类的正确方法是什么?
答案 0 :(得分:0)
您错过了TextTestRunner的实例化:
import unittest
class TestExecuteProc(unittest.TestCase):
def test(self):
self.assertTrue(False)
class TestSetupJobs(unittest.TestCase):
def test(self):
self.assertTrue(False)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSetupJobs)
unittest.TextTestRunner().run(suite)
输出:
F
======================================================================
FAIL: test (__main__.TestSetupJobs)
----------------------------------------------------------------------
Traceback (most recent call last):
File "ops_tests.py", line 9, in test
self.assertTrue(False)
AssertionError: False is not true
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)