Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否可以根据pytest参数更改junit_套件_名称?_Python_Junit_Pytest_Test Suite - Fatal编程技术网

Python 是否可以根据pytest参数更改junit_套件_名称?

Python 是否可以根据pytest参数更改junit_套件_名称?,python,junit,pytest,test-suite,Python,Junit,Pytest,Test Suite,我试图在Jenkins上运行pytest时,以JUnitXML格式创建一个测试报告 默认的测试套件名称是“pytest”,但我想根据参数值更改名称 比如说, 在conftest.py中,我有 def pytest_addoption(parser): parser.addoption("--site", type=str.upper, action="append", default=[], help="testing site") 我想根据站

我试图在Jenkins上运行
pytest
时,以JUnitXML格式创建一个测试报告

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

比如说,

conftest.py
中,我有

def pytest_addoption(parser):
    parser.addoption("--site", type=str.upper, action="append", default=[],
                     help="testing site")
我想根据站点值更改
junit\u suite\u name
选项

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

[pytest]
junit_suite_name = my_suite
或者在命令行上,
-o junit\u suite\u name.

但这样,所有测试用例的名称将始终相同。 有没有一种方法可以有条件地对套件名称进行分组


谢谢

您可以通过在
config.inicfg
dict中设置或更改值,以编程方式更改ini选项。例如,在自定义hookimpl中执行此操作:

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

JUnit报告中的套件名称现在将是
bar
,当您运行
pytest--site=foo
时,您可以通过在
config.ini.ini
dict中设置或更改值,以编程方式更改ini选项。例如,在自定义hookimpl中执行此操作:

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

当您运行
pytest--site=foo

时,JUnit报告中的套件名称现在将是
bar
,因此您希望根据
--site
参数以编程方式设置
JUnit套件名称
,这取决于
--site
参数吗?