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

Ale*_*hen 5 python pycharm python-unittest

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

Pycharm屏幕截图

Joe*_*e P 7

仅使用Python unittest,您就可以装饰要跳过的测试@skip。来自unittest-单元测试框架-Python 2unittest-单元测试框架-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
Run Code Online (Sandbox Code Playgroud)

我认为PyCharm正在向您显示跳过的测试。