Let’s use the following code (conftest.py) :
import random
def test_val():
value = random.random()
assert value < 0.5
Running py.test --junitxml=result.xml conftest.py generates result.xml (when the test passes):
<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" name="" skips="0" tests="1" time="0.047">
<testcase classname="conftest" name="test_val" time="0.0"/>
</testsuite>
Now. What I’d like to be able to do is to store the value generated by test_val() in results.xml. Is there a way to do it ? I can’t seem to find anything related in pytest doc.
The shipped junitxml plugin does not have hooks to add such data
you can print it to stdout though, since that gets added to the junitxml data.
So as long as you print out logs you will at least be able to know the data.