简体   繁体   中英

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

I have multiple pytest scripts that run independently, I want to build a mechanism to add xml attributes to the tests in the script to run in the conftest.py script on collection. So far i've found online a call:

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

that can be run in the pytest_collection_modifyitems hook. but when i try to run this i get:

NameError: name 'request' is not defined

Error Any idea what am i missing?

Dug some more in the documentation and found that if you add this to the conftest.py:

import pytest

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

it does exactly what i need

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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