【问题标题】:Is it possible to change junit_suite_name depending on pytest parameters?是否可以根据 pytest 参数更改 junit_suite_name ?
【发布时间】:2020-04-17 16:57:37
【问题描述】:

我正在尝试在 Jenkins 上运行 pytest 时创建 JUnit XML 格式的测试报告。

默认测试套件名称是“pytest”,但我想根据参数值更改名称。

例如,

conftest.py,我有

def pytest_addoption(parser):
    parser.addoption("--site", type=str.upper, action="append", default=[],
                     help="testing site")

我想根据站点值更改junit_suite_name 选项。

我阅读了 pytest 文档,但发现您可以像这样更改配置文件中的名称

[pytest]
junit_suite_name = my_suite

或在命令行上,-o junit_suite_name.

但是这样一来,所有测试用例的名称将始终相同。 有没有办法有条件地对套件名称进行分组?

谢谢

【问题讨论】:

  • 所以您想以编程方式设置junit_suite_name,具体取决于--site 参数?

标签: python junit pytest test-suite


【解决方案1】:

您可以通过设置或更改 config.inicfg dict 中的值以编程方式更改 ini 选项。比如在自定义pytest_configurehookimpl中做:

def pytest_configure(config):
    if config.option.site == 'foo':
        config.inicfg['junit_suite_name'] = 'bar'

当您运行 pytest --site=foo 时,JUnit 报告中的套件名称现在将是 bar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 2021-12-11
    • 1970-01-01
    • 2019-06-06
    相关资源
    最近更新 更多