【问题标题】:Select suite of tests for coverage with pytest使用 pytest 选择覆盖测试套件
【发布时间】:2021-04-13 15:38:48
【问题描述】:

我正在使用 pytest 运行一组测试,并且还想使用 coverage 包测量其覆盖率。

我的代码中有一些装饰器,使用以下方式将测试分成几个套件:

@pytest.mark.firstgroup
def test_myfirsttest():
    assert True is True

@pytest.mark.secondgroup
def test_mysecondtest():
    assert False is False

我需要找到类似的东西:

coverage run --suite=firstgroup -m pytest

所以在这种情况下,只有第一个测试,因为它在正确的套件中,将用于测试覆盖率。

当我直接使用pytest 时,这些套件可以正常工作,但我不知道如何在coverage 中使用它们

有没有办法配置coverage 来实现这一点?

【问题讨论】:

    标签: python pytest code-coverage coverage.py


    【解决方案1】:

    你可以将任何你想要的参数传递给 pytest。如果这条线有效:

    pytest --something --also=another 1 2 foo bar
    

    然后你可以像这样在覆盖范围内运行它:

    coverage run -m pytest --something --also=another 1 2 foo bar
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 2022-11-01
      • 2020-01-05
      • 2015-12-08
      • 2023-03-05
      相关资源
      最近更新 更多