I am trying to create a junit xml output file in pytest with custom attributes. I searched for answers and found about xml_record_attribute and record_attribute.
def test(record_attribute):
record_attribute('index', '15')
...
At first I thought it would fit to my problem but then I realized it needs to be specified in each test.
I tried to do it with pytest_runtest_call hook so it would add attributes in each test run without the need to explicitly add the attributes in each test. But then it turned out that you can't use fixtures in hook (which makes sense).
Any idea how can I add an attribute to the junit xml output file without duplicating the code?
EDIT: I have another idea of having a decorator which does that.
def xml_decorator(test):
def runner(xml_record_attribute):
xml_record_attribute('index', '15')
test()
reutrn runner
I am trying hook it with pytest_collection_modifyitems and decorate each test but it doesn't work.
def pytest_collection_modifyitems(session, config, items):
for item in items:
item.obj = xml_decorator(item.obj)