unittest之跳过用例(skip)

一、skip装饰器

skip装饰器一共有四个

**`   @``unittest.``skip`(*reason*)**

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

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

*   **`@``unittest.``skipIf`(*condition*, *reason*)**

*   Skip the decorated test if *condition* is true.

    翻译:*condition*为true的时候跳过

*   **`@``unittest.``skipUnless`(*condition*, *reason*)**

*   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了。)

二、参考代码:

# 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()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,195评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,543评论 0 23
  • 沈华立(正其心),天贝车业,盛和塾224期学员,【日精打卡第22天】 《六项精进》2遍共66遍 《大学》2遍共66...
    沈华立阅读 1,202评论 0 0
  • 雷纳在《猎凶风河谷》里对失去女儿的印第安父亲说了一段话。 他说“我有一个好消息和一个坏消息。坏消息是你不可能回...
    药师哎阅读 3,434评论 0 0
  • 你是不是跟我一样,觉得每天好像都是一个样子。 时钟滴答着时间,脚步拖沓着脚印。 每天的风景不过公司和家的两点一线,...
    知更喵阅读 3,685评论 0 1

友情链接更多精彩内容