我正在编写一个 PyTest 插件,其中使用此函数实现了不同的自定义标记:
def pytest_configure(config):
config.addinivalue_line("markers", "title(a_title): a title to present the test case")
Run Code Online (Sandbox Code Playgroud)
然后,使用这些标记为 jUnit 输出中的每个测试用例添加自定义属性。
现在,由于我发现自己经常使用parametrize
标记,因此我想用参数化标记中定义的参数值填充标记的一部分。
这是我想要实现的目标的一个例子。代码如下:
class TestClass:
@pytest.mark.parametrize("param", ["value1", "value2"])
@pytest.mark.title(f"This test case checks that param is {param}")
def test_simple_test_case(self, param):
pass
Run Code Online (Sandbox Code Playgroud)
我希望 XML 输出像这样填充:
<testcase classname="test_example.TestClass" name="test_simple_test_case[value1]" time="0.001">
<properties>
<property name="title" value="This test case checks that param is value1"/>
</properties>
</testcase>
<testcase classname="test_example.TestClass" name="test_simple_test_case[value2]" time="0.001">
<properties>
<property name="title" value="This test case checks that param is value2"/>
</properties>
</testcase>
<testcase classname="test_example.TestClass" name="test_simple_test_case[value3]" time="0.001"> …
Run Code Online (Sandbox Code Playgroud)