【问题标题】:Python: is there a better way to skip the test module?Python:有没有更好的方法来跳过测试模块?
【发布时间】:2013-05-21 12:43:45
【问题描述】:

我读了How do I skip a whole Python unittest module at run-time?,这似乎不是一个非常整洁的方式

在 Java 中,你只需要在测试类上说 @Ignore,整个测试类就会被忽略

有没有更好的方法来skip整个测试模块或者我应该这样做

class TestMe():
  @unittest.skip
  def test_a(self):
    pass

  @unittest.skip
  def test_b(self):
    pass
  ...

通过在模块的所有测试中添加@unittest.skip

【问题讨论】:

  • 呃……你是在自言自语吗?
  • 有一个人,但他似乎删除了他的评论;)

标签: python


【解决方案1】:

只需使用类上的装饰器,as per the docs

@unittest.skip("showing class skipping")
class MySkippedTestCase(unittest.TestCase):
    def test_not_run(self):
        pass

【讨论】:

    【解决方案2】:

    根据评论,以下作品

    @unittest.skip
    class TestMe():
      def test_a(self):
        pass
    
      def test_b(self):
        pass
      ...
    

    通过在类而不是每个方法上添加注释@unittest.skip

    【讨论】:

      猜你喜欢
      • 2014-08-31
      • 2019-08-26
      • 2013-08-18
      • 2018-02-15
      • 1970-01-01
      • 2015-08-09
      • 2012-04-28
      • 2020-05-01
      • 2010-12-27
      相关资源
      最近更新 更多