码迷,mamicode.com
首页 > 编程语言 > 详细

python单元测试框架-unittest(五)之跳过测试和预期失败

时间:2018-07-23 19:12:25      阅读:438      评论:0      收藏:0      [点我收藏+]

标签:rdo   class   reason   set   pytho   color   utf-8   odi   span   

概要

  • @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()

 

python单元测试框架-unittest(五)之跳过测试和预期失败

标签:rdo   class   reason   set   pytho   color   utf-8   odi   span   

原文地址:https://www.cnblogs.com/shenhainixin/p/9356293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!