标签:set info 方式 and strong ror self 需要 跳过
1.无条件跳过某方法
@unittest.skip("skipping")
2.使用变量的方式,指定忽略测试方法
a=10 @unittest.skipIf(a > 5, "condition is not satisfied!")
表示if a>5为真,就跳过此方法
3.指定测试平台忽略测试方法
@unittest.skipUnless(sys.platform.startswith("Linux"), "requires Linux")
如果不是liunx ,就直接跳过,python可以使用sys,查看自己的平台信息

import random
import unittest
import sys
class TestSequenceFunctions(unittest.TestCase):
a = 10
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))
# 如果变量a > 5,则忽略该测试方法
@unittest.skipIf(a > 5, "condition is not satisfied!")
def test_choice(self):
element = random.choice(self.seq)
self.assertTrue(element in self.seq)
# 除非执行测试用例的平台是Linux平台,否则忽略该测试方法 win32是windows
@unittest.skipUnless(sys.platform.startswith("Linux"), "requires Linux")
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()
测试结果

标签:set info 方式 and strong ror self 需要 跳过
原文地址:https://www.cnblogs.com/chongyou/p/12497197.html