【问题标题】:How can I mark tests as "long" and skip them?如何将测试标记为“长”并跳过它们?
【发布时间】:2018-10-13 19:50:42
【问题描述】:

我通常使用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?

【问题讨论】:

标签: pytest python-decorators tox


【解决方案1】:

我找到了一半的答案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 =================

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-12-20
  • 2019-09-28
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
  • 2013-06-11
  • 2013-03-28
  • 1970-01-01
相关资源
最近更新 更多