unittet skip 测试用例

来源:互联网 发布:matlab 数据拟合 编辑:程序博客网 时间:2024/06/08 00:37

unittet可以分无条件忽略和有条件忽略,通过装饰器实现
介绍:  
@unittest.skip(reason): skip(reason)装饰器:无条件跳过装饰的测试,并说明跳过测试的原因。
@unittest.skipIf(reason): skipIf(condition,reason)装饰器:条件为真时,跳过装饰的测试,并说明跳过测试的原因。
@unittest.skipUnless(reason): skipUnless(condition,reason)装饰器:条件为假时,跳过装饰的测试,并说明跳过测试的原因。
@unittest.expectedFailure(): expectedFailure()测试标记为失败。

代码示例:
忽略测试case

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.expectedFailure()      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




0 0