可以使用unitest.skip
装饰器族跳过test method
或者test class
,这些装饰器包括:
① @unittest.skip(reason)
:无条件跳过测试,reason
描述为什么跳过测试
② @unittest.skipif(conditition,reason)
:condititon
为true
时跳过测试
③ @unittest.skipunless(condition,reason)
:condition
不是true
时跳过测试
class MyTestCase(unittest.TestCase):
@unittest.skip("demonstrating skipping")
def test_nothing(self):
self.fail("shouldn't happen")
@unittest.skipIf(mylib.__version__ < (1, 3),
"not supported in this library version")
def test_format(self):
# Tests that work for only a certain version of the library.
pass
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
def test_windows_support(self):
# windows specific testing code
pass
@unittest.skip("showing class skipping")
class MySkippedTestCase(unittest.TestCase):
def test_not_run(self):
pass