#跳过测试skip和预期失败 import unittest #@unittest.skip #直接跳过测试 class Test1(unittest.TestCase): @classmethod def setUpClass(cls): print('在类运行前执行') @classmethod def tearDownClass(cls): print('在类运行后执行') def setUp(self): print('test1 start') @unittest.skipUnless(1<0,'条件为假,则跳过测试') def test_a(self): print('this is test a') @unittest.expectedFailure #预期失败 def test_c(self): print('this is test c') def tearDown(self): print('test1 end') print('===================') class Test2(unittest.TestCase): def setUp(self): print('test2 start') @unittest.skipIf(1>0,'条件为真,则跳过测试') def test_b(self): print('this is test b') def test_d(self): print('this is test d') def tearDown(self): print('test2 end') print('===================') if __name__=='__main__': unittest.main()