unittest跳过用例

  
  在做自动化测试的时候,可能会遇到一些用例中间不用回归,想要进行跳过。
这时就要用到unittest自动跳过用例的装饰器方法。

import unittest


class SkipCase(unittest.TestCase):

    @unittest.skip("强制性跳过")
    def test01(self):
        """
            多用于,不想执行的用例,但是还不能删除的时候
        :return:
        """
        print("第一条用例跳过")

    @unittest.skipIf(True, '条件为真的时候跳过')
    def test02(self):
        """
            条件为真的时候跳过
        :return:
        """
        a = 'hello'
        b = 'hello'
        self.assertEqual(a, b)
        print("第二条用例跳过")

    @unittest.skipUnless(False, '条件为假的时候跳过')
    def test03(self):
        """
             条件为假的时候跳过
        :return:
        """
        a = 'Python'
        b = 'Java'
        try:
            self.assertEqual(a, b)
        except Exception as msg:
            print('错误信息:{0}'.format(msg))
        print("第三条用例跳过")

    def test04(self):
        a = 'PLSQL'
        b = 'Oracle PLSQL'
        self.assertIn(a, b)
        print("第四条用例不跳过")


if __name__ == '__main__':
    unittest.main()
原文地址:https://www.cnblogs.com/wzhqzm/p/13560965.html