Skip to content

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

Open

Description

@mszpala

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.

Activity

  1. raphaelcastaneda commented on Jul 22, 2020

    @raphaelcastaneda

    Does the record_property fixture fail in the same way?

  2. raphaelcastaneda commented on Jul 22, 2020

    @raphaelcastaneda

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

  3. gs202 commented on May 10, 2021

    @gs202

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

  4. added
    plugin: xdist
    type: bug
    on May 10, 2021
  5. RonnyPfannschmidt commented on May 10, 2021

    @RonnyPfannschmidt
    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

  6. gs202 commented on May 11, 2021

    @gs202

    @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

  7. RonnyPfannschmidt commented on May 11, 2021

    @RonnyPfannschmidt
    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

  8. gs202 commented on May 11, 2021

    @gs202

    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

  9. RonnyPfannschmidt commented on May 11, 2021

    @RonnyPfannschmidt
    Member

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

  10. gs202 commented on May 11, 2021

    @gs202
  11. nicoddemus commented on May 18, 2021

    @nicoddemus
    Member

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

  12. rom1011 commented on Jan 12, 2022

    @rom1011

    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>
    
  13. ChintanDonda commented on May 12, 2022

    @ChintanDonda

    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?

  14. nicoddemus commented on May 12, 2022

    @nicoddemus
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: xdisttype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions