'include xfail error info in pytest junit output?

Pytest's junitxml output records an xfailed test as skipped, but I can use the type (<skipped type="pytest.xfail" message="" />) in my tools to tell it's really xfailed.

What I'm missing is details on why it failed -- is there a way to get pytest's junit output to include the error, like it does for failed tests?

Specifically, in the example below I'd love if asserting False in aaa could appear in the output.

test_abc.py:

import pytest


@pytest.mark.xfail
def test_aaa():
    assert False, 'aaa xfails'

def test_bbb():
    assert False, 'bbb reall fails'

pytest test_abc.py --junitxml=output.xml

output.xml:

<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="1" skipped="1" tests="2" time="0.154" timestamp="2022-02-12T08:27:20.645265" hostname="Davids-MacBook-Pro.local"><testcase classname="test_abc" name="test_aaa" time="0.001"><skipped type="pytest.xfail" message="" /></testcase><testcase classname="test_abc" name="test_bbb" time="0.001"><failure message="AssertionError: asserting False in bbb&#10;assert False">def test_bbb():
&gt;       assert False, 'asserting False in bbb'
E       AssertionError: asserting False in bbb
E       assert False

test_abc.py:9: AssertionError</failure></testcase></testsuite></testsuites>```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source