unittest 中用于跳过 test method, test class,的相关装饰器

可以使用unitest.skip装饰器族跳过test method或者test class,这些装饰器包括:
@unittest.skip(reason):无条件跳过测试,reason描述为什么跳过测试
@unittest.skipif(conditition,reason):condititontrue时跳过测试
@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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值