概要
- @unittest.skip(reason): skip(reason)装饰器:直接跳过测试,并说明跳过测试的原因。
- @unittest.skipIf(reason): skipIf(condition,reason)装饰器:条件为真时,跳过测试,并说明跳过测试的原因
- @unittest.skipUnless(reason): skipUnless(condition,reason)装饰器:条件为假时,跳过测试,并说明跳过测试的原因
- @unittest.expectedFailure(): expectedFailure()测试标记为失败。
实例
1 #coding=utf-8 2 import unittest 3 class Test1(unittest.TestCase): 4 def setUp(self): 5 print("Test1 start") 6 # @unittest.skipIf(4>3,"skip Test_d") 7 def test_c(self): 8 print("test_c") 9 @unittest.skipUnless(1<0,"skip test_b") 10 def test_b(self): 11 print("test_b") 12 13 def tearDown(self): 14 print("test end") 15 16 # @unittest.skip("skip Test_2") 17 class Test2(unittest.TestCase): 18 def setUp(self): 19 print("Test2 start") 20 21 def test_3(self): 22 print("test_3") 23 @unittest.expectedFailure 24 def test_2(self): 25 print("test_2") 26 27 def tearDown(self): 28 print("Test2 end!") 29 if __name__==‘__main__‘: 30 unittest.main()
原文地址:https://www.cnblogs.com/shenhainixin/p/9356293.html
时间: 2024-10-07 05:34:46