如何将测试标记为 "long" 并跳过它们?

How can I mark tests as "long" and skip them?

我通常 运行 我的测试使用 tox 调用 pytest。此设置在许多项目中都能正常工作。然而,在某些项目中,我有一些测试需要很长时间(几分钟)。我不想每次都 运行 他们。我想装饰测试只要。

像这样:

$ tox --skip-long

# core modules
import unittest

class Foo(unittest.TestCase):

    def test_bar(self):
        ...

    @long
    def test_long_bar(self):
        ...

How can I do this?

我找到了一半的答案here:

@pytest.mark.long

并执行

pytest -v -m "not long"

到 运行 上 tox (source):

tox -- -m "not long"

输出如下所示:

============================ 2 tests deselected ==================================
========== 20 passed, 2 deselected, 7 warnings in 151.93 seconds =================