概要
- unittest.skip() 直接跳过测试
- unittest.skipIf() 条件为真,跳过测试
- unittest.skipUnless 条件为假,跳过测试
- unittest.expectedFailure 预期设置失败
import unittest
class Test1(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("model test start!>>>")
@classmethod
def tearDownClass(cls):
print("model test end!>>>")
def setUp(self):
print("test start")
def test_c(self):
print("test_c")
@unittest.expectedFailure
def test_b(self):
print("test_b")
def tearDown(self):
print("test end")
class Test2(unittest.TestCase):
def setUp(self):
print("Test2 start")
@unittest.skipIf(4 > 3,'条件为真时,跳过test_d')
def test_d(self):
print("test_d")
@unittest.skipUnless(1 < 0, '条件为假时,跳过test_a')
def test_a(self):
print("test_a")
@unittest.skip('跳过test_e')
def test_e(self):
print("test_e")
def tearDown(self):
print("Test2 end!")
if __name__ == '__main__':
# 默认顺序:0-9,a-z
unittest.main()
# # 按照装载用例的顺序执行
# suite = unittest.TestSuite()
# suite.addTest(Test2('test_d'))
# suite.addTest(Test1('test_b'))
# suite.addTest(Test2('test_a'))
# suite.addTest(Test1('test_c'))
# runner = unittest.TextTestRunner()
# runner.run(suite)