前言

当测试用例写完后,有些模块有改动时候,会影响到部分用例的执行,这个时候我们希望暂时跳过这些用例。

或者前面某个功能运行失败了,后面的几个用例是依赖于这个功能的用例,如果第一步就失败了,后面的用例也就没必要去执行了,直接跳过就行,节省用例执行时间。

一、skip装饰器

skip装饰器一共有四个

   @unittest.skip(reason)

  • Unconditionally skip the decorated test. reason should describe why the test is being skipped.

    翻译:无条件跳过用例,reason是说明原因

  • @unittest.skipIf(conditionreason)

  • Skip the decorated test if condition is true.

    翻译:condition为true的时候跳过

  • @unittest.skipUnless(conditionreason)

  • Skip the decorated test unless condition is true.

    翻译:condition为False的时候跳过

  • @unittest.expectedFailure

  • Mark the test as an expected failure. If the test fails when run, the test is not counted as a failure.

    翻译:断言的时候跳过(暂时不知道有啥用,没看懂,貌似断言失败,也变成用例pass了。)

二、skip案例

运行结果:

测试1
测试4
.ssx
----------------------------------------------------------------------
Ran 4 tests in 0.003s

OK (skipped=2, expected failures=1)

三、跳过整个测试类

四、参考代码:

# coding:utf-8
import unittest
class Test(unittest.TestCase):

@unittest.skip(u"无条件跳过此用例")
    def test_1(self):
        print "测试1"

@unittest.skipIf(True, u"为True的时候跳过")
    def test_2(self):
        print "测试2"

@unittest.skipUnless(False, u"为False的时候跳过")
    def test_3(self):
        print "测试3"

@unittest.expectedFailure
    def test_4(self):
        print "测试4"
        self.assertEqual(2, 4, msg=u"判断相等")

if __name__ == "__main__":
    unittest.main()

最新文章

  1. HTML5之文件API
  2. asp.net type=file在上传图片到服务器
  3. css3 box-sizing属性
  4. (BZOJ4538)HNOI2016 网络
  5. IIS7 ASP.NET 未被授权访问所请求的资源
  6. N皇后问题2
  7. 使用for xml path 分组查询
  8. 出力csv
  9. weblogic开发模式与生产模式介绍
  10. VS2019 更新MSDN并创建快捷方式
  11. [ 9.29 ]CF每日一题系列—— 765B字符串规律
  12. js 时间格式化和时间戳
  13. Unable to handle kernel NULL pointer dereference at virtual address 00000000问题的解决
  14. ASP.NET MVC Bundles 之学习笔记
  15. 实验三 Java猜数字游戏开发
  16. 每日英语:He Diets, She Diets: More Weight-Loss Plans Target Men
  17. JavaScript 中 this 的用法
  18. 027_编写MapReduce的模板类Mapper、Reducer和Driver
  19. oracle如何查看表空间
  20. 1060: [ZJOI2007]时态同步

热门文章

  1. centos tomcat开机自启
  2. APP与智能手表是如何通信的【本文摘抄自深圳尚锐科技】
  3. mysql 5.7 Access denied for user 'root'@'localhost' solution
  4. Mapreduce简要原理与实践
  5. 周记【距gdoi:126天】
  6. [ZJOI2008]骑士 DP dfs
  7. CVPR2014 Objectness 源码转换(完整版) VS2012 X64 –>win32
  8. hadoop SecondNamenode 详解
  9. CMU Bomblab 答案
  10. bzoj 1517 [POI2006]Met 贪心