Skip to content

Conversation

EnricoMi
Copy link
Collaborator

@EnricoMi EnricoMi commented Dec 20, 2024

For the sake of consistency, JUnitXml.fromfile, JUnitXml.fromstring and JUnitXml.fromroot should always return a JUnitXml instance. Currently, when the root element of the XML document is a <TestSuite> tag, it would return a TestSuite instance. This causes confusion: #110, #111, #140.

This fact affects behavior of iterating the instance (as given in the examples), it iterates TestCase instances, not TestSuite instances:

from junitparser import JUnitXml

xml = JUnitXml.fromfile('/path/to/junit.xml')
for suite in xml:
    # handle suites
    for case in suite:
        # handle cases

https://github.com/weiwei/junitparser?tab=readme-ov-file#read-and-manipulate-existing-junitxunit-xml-files

Note: This is a breaking change.

Fixes #110
Fixes #111
Fixes #140

@EnricoMi EnricoMi force-pushed the from-methods-return-type branch from 5ec9ccb to 2095372 Compare January 29, 2025 11:20
@EnricoMi EnricoMi marked this pull request as ready for review January 29, 2025 11:20
Copy link

github-actions bot commented Jan 29, 2025

Test Results

   48 files  ± 0     48 suites  ±0   3m 25s ⏱️ +2s
  123 tests + 1    123 ✅ + 1    0 💤 ±0  0 ❌ ±0 
5 904 runs  +48  5 733 ✅ +48  171 💤 ±0  0 ❌ ±0 

Results for commit b2d41f3. ± Comparison against base commit bca6112.

♻️ This comment has been updated with latest results.

@EnricoMi EnricoMi force-pushed the from-methods-return-type branch from 2095372 to 5cbf10d Compare January 29, 2025 11:32
@EnricoMi
Copy link
Collaborator Author

@weiwei what are your thoughts? This is a breaking change so the upcoming v4 release would be a nice target.

natifridman added a commit to natifridman/release that referenced this pull request May 27, 2025
Junitparser's verify subcommand fails if there is only one test suite
This can be removed when weiwei/junitparser#142 is merged
openshift-merge-bot bot pushed a commit to openshift/release that referenced this pull request May 27, 2025
Junitparser's verify subcommand fails if there is only one test suite
This can be removed when weiwei/junitparser#142 is merged
abraham2512 pushed a commit to abraham2512/release that referenced this pull request May 29, 2025
Junitparser's verify subcommand fails if there is only one test suite
This can be removed when weiwei/junitparser#142 is merged
Earlier versions return a `TestSuite` instance when the root of the file / string / element is a `<TestSuite>`.
A `JUnitXml` instance has already been returned by earlier versions when the root of the file / string / element is a `<TestSuites>`.

If you want to create a `TestSuite` instance from a `<TestSuite>` element, use
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good way to preserve original behavior if needed.

@weiwei weiwei merged commit 2e3b756 into master Jun 22, 2025
38 checks passed
@weiwei weiwei deleted the from-methods-return-type branch June 22, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants