【问题标题】:How to ignore some unittest test in Pycharm 2017.1?如何忽略 Pycharm 2017.1 中的一些单元测试?
【发布时间】:2017-11-27 04:16:41
【问题描述】:

Pycharm 测试运行窗口中有一个“Show Ignored”按钮。我想知道,如何将某些测试标记为忽略?

【问题讨论】:

  • 有没有办法让pyCharm隐藏skitepd测试父组?例如,如果一个测试类包含跳过的测试,不要将整个类标记为已跳过,而是将其显示为通过?

标签: python pycharm python-unittest


【解决方案1】:

仅使用 Python unittest,您可以使用 @skip 装饰要跳过的测试。来自unittest — Unit testing framework — Python 2unittest — Unit testing framework — Python 3

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

我假设 PyCharm 正在向您显示跳过的测试。

【讨论】:

  • 谢谢。我什至没有尝试向谷歌询问简单的“python skip unittest”。我一直在寻找“忽略”它们。真丢人。
  • 是的,我不得不挖掘一下才能记住它是跳过。 @ignore 可能是一个更好的选择。 :)
猜你喜欢
  • 2017-04-01
  • 1970-01-01
  • 2010-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
  • 1970-01-01
相关资源
最近更新 更多