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?
CodePudding user response:
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