被跳过的用例 / 类 / 模块,与之相应的 setUp() / tearDown()、setUpClass / tearDownClass()、setUpModule() / tearDownModule() 也不会被执行。
6种跳过用例的方法
- 直接强制跳过
# reason 为说明跳过原因
@unittest.skip(reason)
实例
import unittest
class myTestCase(unittest.TestCase):
def test01(self):
print('test01')
@unittest.skip('跳过test02')
def test02(self):
print('test02')
def test03(self):
print('test03')
if __name__ == '__main__':
unittest.main()
执行结果
Ran 3 tests in 0.048s
OK (skipped=1)
Process finished with exit code 0
test01
Skipped: 跳过test02
test03
- 给定条件成立时跳过
# 条件condition为True时跳过
@unittest.skipIf(conidition, reason)
实例