Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record_xml_attribute not visible in JUnit XML when using pytest-xdist #8654

Open
mszpala opened this issue Jun 2, 2020 · 13 comments
Open

record_xml_attribute not visible in JUnit XML when using pytest-xdist #8654

mszpala opened this issue Jun 2, 2020 · 13 comments
Labels
plugin: xdist related to the xdist external plugin type: bug problem that needs to be addressed

Comments

@mszpala
Copy link

mszpala commented Jun 2, 2020

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.

@raphaelcastaneda
Copy link

raphaelcastaneda commented Jul 22, 2020

Does the record_property fixture fail in the same way?

@raphaelcastaneda
Copy link

To answer my own question: no it does not.
record_property was updated to add pytest-xdist support here: 8b49ddf

@gs202
Copy link

gs202 commented May 10, 2021

I've encountered the same issue, will it be resolved?

@RonnyPfannschmidt RonnyPfannschmidt transferred this issue from pytest-dev/pytest-xdist May 10, 2021
@RonnyPfannschmidt RonnyPfannschmidt added plugin: xdist related to the xdist external plugin type: bug problem that needs to be addressed labels May 10, 2021
@RonnyPfannschmidt
Copy link
Member

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

@gs202
Copy link

gs202 commented May 11, 2021

@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

@RonnyPfannschmidt
Copy link
Member

@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

@gs202
Copy link

gs202 commented May 11, 2021

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

@RonnyPfannschmidt
Copy link
Member

@gs202 at first glance that is a different issue, please open a new one

@gs202
Copy link

gs202 commented May 11, 2021

@RonnyPfannschmidt #8662

@nicoddemus
Copy link
Member

nicoddemus commented May 18, 2021

Perhaps this is the same issue as #8662 (comment)?

@rom1011
Copy link

rom1011 commented Jan 12, 2022

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>

@ChintanDonda
Copy link

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?

@nicoddemus
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: xdist related to the xdist external plugin type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

7 participants