zoukankan      html  css  js  c++  java
  • seslenium

    运行测试时,可以设置直接跳过某些测试用例,或者当条件符合时执行或不执行。unittest提供了实现这些需求的装饰器。

    • unittest.skip(reason) 无条件地跳过
    • unittest.skipIf(condition, reason) 条件为真时,跳过
    • unittest.skipUnless(condition, reason) 条件为真时,执行
    • unittest.expectedFailure 不管执行结果如何,统一标记为失败
     1 import unittest
     2 
     3 class MyTest(unittest.TestCase):
     4     def setUp(self):
     5         pass
     6 
     7     def tearDown(self):
     8         pass
     9 
    10     @unittest.skip('无条件跳过')
    11     def test1(self):
    12         print('test1')
    13 
    14     @unittest.skipIf(3 > 2, '条件为True时,跳过')
    15     def test2(self):
    16         print('test2')
    17 
    18     @unittest.skipUnless(3 > 2, '当条件为True时,执行')
    19     def test3(self):
    20         print('test3')
    21 
    22     @unittest.expectedFailure
    23     def test4(self):
    24         print('test4')
    25 
    26 
    27 if __name__ == '__main__':
    28     unittest.main()

    这些方法同样可以作用于测试类,只需在类上定义即可

    1 import unittest
    2 
    3 @unittest.skip('直接跳过该类')
    4 class MyTest(unittest.TestCase):
    5     pass
  • 相关阅读:
    学习vue_01
    练习题 vue_01:
    测试
    django小结
    BBS_02day
    BBS 03day
    力扣(LeetCode)412. Fizz Buzz
    力扣(LeetCode)415. 字符串相加
    力扣(LeetCode)448. 找到所有数组中消失的数字
    力扣(LeetCode)453. 最小移动次数使数组元素相等
  • 原文地址:https://www.cnblogs.com/xiaochongc/p/12594992.html
Copyright © 2011-2022 走看看