如何忽略Pycharm 2017.1中的某些单元测试?

时间:2017-06-23 14:28:39

标签: python pycharm python-unittest

有一个按钮"显示忽略"在Pycharm测试运行窗口中。我想知道,如何将某些测试标记为忽略?

Pycharm screenshot

1 个答案:

答案 0 :(得分:6)

只需使用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正在向您展示跳过的测试。