【问题标题】:pytest test with --ignore and --junitxml generate xml with ignored tests使用 --ignore 和 --junitxml 的 pytest 测试生成带有忽略测试的 xml
【发布时间】:2020-05-08 05:25:16
【问题描述】:

我正在使用带有 --ignore 和 --junitxml 选项的 pytest 来生成测试用例的报告,这些测试用例不会被忽略,但是当我的报告生成时,它也会考虑到被忽略的测试。

我正在使用以下命令

pytest --ignore=tests/test_a.py --junitxml=pytest_not_a.xml

【问题讨论】:

  • 嗨@MrBeanBremen,我可以运行上面的pytest命令,但是当junit生成关于gitlab报告的报告时,它会将--ignore测试文件的测试保留为跳过的测试,它也将这些测试纳入百分比计算。
  • 嗯,我不知道——我只是在本地测试过,生成的xml中没有引用忽略的测试。抱歉,不知道您的设置有什么不同...

标签: python-3.x pytest


【解决方案1】:

我可以使用pytest.mark.httpapi 解决这个问题,而不是在每个测试套件上都使用它。我添加了pytest_collection_modifyingitems,它将标记放在运行时的测试上。

def pytest_collection_modifyitems(config, items):
    for item in items:
        if 'test_a.py' in str(item.fspath):
            mark = getattr(pytest.mark, "httpapi")
            item.add_marker(mark)
            item.add_marker(pytest.mark.common)

现在上面的命令会稍微改变一下

py.test -v -m "not httpapi" --junitxml=pytest_not_a.xml。现在 Junit gitlab 工件只接受处理过的测试,并且不包括成功率计算中跳过的测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    相关资源
    最近更新 更多