pytest-dev / pytest-dev/pytest

subtests not itemized in Junit XML

Open
#13,876 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: junitxml plugin: subtests
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Testing with tip-of-main to try out new subtests integration. Simple subtest example

def test_subtests(subtests):
    """Simple subtest example"""
    for i in range(2):
        with subtests.test(msg="is_even", i=i):
            assert i % 2 == 0, f"{i} is odd"

I expect each subtest to appear as a in a generated JUnit XML. Instead, only the top level is:

<testcase classname="samples.test_sample" name="test_subtests" time="0.006">
<failure message="AssertionError: 1 is odd&#10;assert (1 % 2) == 0">subtests = &lt;_pytest.subtests.Subtests object at 0x103b1d580&gt;

    def test_subtests(subtests):
        """Simple subtest example"""
        for i in range(2):
            with subtests.test(msg="is_even", i=i):
&gt;               assert i % 2 == 0, f"{i} is odd"
E               AssertionError: 1 is odd
E               assert (1 % 2) == 0

samples/test_sample.py:87: AssertionError</failure><system-out>--------------------------------- Captured Log ---------------------------------

</system-out>
<failure message="contains 1 failed subtest">contains 1 failed subtest</failure>
<system-out>--------------------------------- Captured Log ---------------------------------

</system-out>
</testcase>
  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the subtest example in samples/test_sample.py, especially test_subtests at line 87, and inspect the generated JUnit XML. Trace how pytest's subtests integration is represented by the JUnit reporting path. Done means each subtest appears as its own while the report still represents the top-level test correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.