跳过执行用例

 

跳过某条用例使用是skip代码如下:

 

 

import unittest
import random
import sys


class TestSequenceFunctions(unittest.TestCase):
    a = 1

    def setUp(self):
        self.seq = list(range(10))

    @unittest.skip('skipping')
    def test_shuffle(self):
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, list(range(10)))
        self.assertRaises(TypeError, random.shuffle, (1, 2, 3))

    # 如果变量》5,则忽略测试方法
    @unittest.skipIf(a > 5, 'condition is not satisfied!')
    def test_chioce(self):
        element = random.choice(self.seq)
        self.assertTrue(element in self.seq)

    # 除法执行测试用例的平台是windows平台,否则忽略该测试方法!
    @unittest.skipUnless(sys.platform.startswith('linux'), 'requires windows')
    def test_sample(self):
        with self.assertRaises(ValueError):
            random.sample(self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assertTrue(element in self.seq)


if __name__ == '__main__':
    # unittest.main()
    testCase = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
    suite = unittest.TestSuite(testCase)
    unittest.TextTestRunner(verbosity=2).run(suite)

 

 

你可能感兴趣的:(selenium)