繁体   English   中英

在 conftest.py 中将多个 XML 属性添加到 pytest xml

[英]Adding multiple XML attributes to a pytest xml in conftest.py

我有多个独立运行的 pytest 脚本,我想构建一种机制,将 xml 属性添加到脚本中的测试中,以便在收集时在 conftest.py 脚本中运行。 到目前为止,我在网上找到了一个电话:

request.config._xml.node_reporter(item.nodeid).add_attribute('spam', 'eggs')

可以在pytest_collection_modifyitems钩子中运行。 但是当我尝试运行它时,我得到:

NameError: name 'request' is not defined

错误知道我错过了什么吗?

在文档中挖掘了更多内容,发现如果将其添加到 conftest.py 中:

import pytest

@pytest.fixture(autouse=True)
def record_index(record_xml_attribute):
    record_xml_attribute('index', '15')

它正是我需要的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM