unittest框架-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.

    翻译:预期设置失败,跳过测试


Skip规则设定案例


猜你喜欢

转载自blog.csdn.net/florachy/article/details/80055332
今日推荐