pytest
pytest copied to clipboard
record_xml_attribute not visible in JUnit XML when using pytest-xdist
Currently pytest-xdist is working without a problem with record_property, but it does not save the values using record_xml_attribute fixture.
Here's the code to reproduce this issue
import pytest
def test_xdist_xml(record_xml_attribute):
record_xml_attribute("key", 1)
I run this this test twice using following command:
py.test test_example.py --junit-xml=without_xdist.xml and then py.test test_example.py --junit-xml=with_xdist.xml -n auto
without_xdist.xml
<testcase classname="test_example" file="test_example.py" key="1" line="2" name="test_xdist_xml" time="0.001"></testcase>
with_xdist.xml
<testcase classname="test_example" file="test_example.py" line="2" name="test_xdist_xml" time="0.002"></testcase>
So it looks like key="1" is missing from junit XML when using xdist.
I've tested it using latest pytest (5.4.2) and pytest-xdist (1.32.0) Thanks for any help.
Does the record_property fixture fail in the same way?
To answer my own question: no it does not.
record_property was updated to add pytest-xdist support here: https://github.com/pytest-dev/pytest/commit/8b49ddfa585e8dee77ba3aeef654598e0052237e
I've encountered the same issue, will it be resolved?
just took note on this again @raphaelcastaneda thanks for the analysis, moved to the main repo as we have to fix this inside of pytes
@RonnyPfannschmidt it seems that i can update existing attributes but can't add new ones. another note, although i use xdist in my project - i've tried to update the xml with a single test running
@gs202 im not sure what you are referring to here
the issue is primarily about the record_xml_attribute fixture not using a storage/transport mechanism that that transfers via xdist
I'll use an example for this test:
class TestClass:
def test_foo(self):
assert True
Here is the junit xml file without using record_xml_attribute:
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite errors="0" failures="0" hostname="myhost" name="pytest" skipped="0" tests="1"
time="0.438" timestamp="2021-05-11T11:17:44.943549">
<testcase classname="tests.rba.test_me.TestClass" name="test_foo" time="0.015"/>
</testsuite>
</testsuites>
After adding record_xml_attribute to the test:
class TestClass:
def test_foo(self, record_xml_attribute):
record_xml_attribute("assertions", "REQ-1234")
record_xml_attribute("classname", "custom_classname")
assert True
The xml file will be:
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite errors="0" failures="0" hostname="myhost" name="pytest" skipped="0" tests="1"
time="0.415" timestamp="2021-05-11T11:19:42.484839">
<testcase classname="custom_classname" name="test_foo" time="0.022"/>
</testsuite>
</testsuites>
As you can see the classname attribute was overridden but the assertions doesn't exist
@gs202 at first glance that is a different issue, please open a new one
@RonnyPfannschmidt https://github.com/pytest-dev/pytest/issues/8662
Perhaps this is the same issue as https://github.com/pytest-dev/pytest/issues/8662#issuecomment-841665792?
I would like to follow up on this issue when using xdist like mentioned in the subject:
% cat test.py
class TestClass:
def test_foo(self, record_xml_attribute):
record_xml_attribute("assertions", "REQ-1234")
record_xml_attribute("classname", "custom_classname")
assert True
Running
py.test test.py --junitxml=test.xml --no-header -o junit_family=xunit1
generates
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite errors="0" failures="0" hostname="XXX" name="pytest" skipped="0" tests="1" time="0.020" timestamp="2022-01-12T15:14:35.998813">
<testcase assertions="REQ-1234" classname="custom_classname" file="test.py" line="2" name="test_foo" time="0.007"/>
</testsuite>
</testsuites>
While enabling xdist
py.test test.py --junitxml=test_xdist.xml --no-header -o junit_family=xunit1 -n=1
does not generate the assertion and does not update the classname attribute:
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite errors="0" failures="0" hostname="XXX" name="pytest" skipped="0" tests="1" time="3.299" timestamp="2022-01-12T15:19:43.570723">
<testcase classname="test.TestClass" file="test.py" line="2" name="test_foo" time="0.001"/>
</testsuite>
</testsuites>
Same issue for me as well. pytest-xdist does not add record_xml_attribute to the xml output file.
I tried with all of these, but none of them working:
py.test test.py --junitxml=test.xml --no-header -o junit_family=xunit1
py.test test.py --junitxml=test.xml --no-header -o junit_family=xunit2
py.test test.py --junitxml=test.xml --no-header -o junit_family=legacy
Any solution?
Unfortunately record_xml_attribute does not work with xdist under the current design/implementation.
I think we should at least raise an error/warning if record_xml_attribute is used with xdist.