weiwei / junitparser

Parses JUnit/xUnit Result XML files with ease
https://junitparser.readthedocs.io
Other
120 stars 52 forks source link

Junit XML with TestSuites vs TestSuite as root element #96

Closed guilhem-martin closed 11 months ago

guilhem-martin commented 2 years ago

Hello,

As JUnit XML file inputs, I get sometimes TestSuite as root and sometimes TestSuites, which is as expected from the JUnit XSD file definition.

To be able to know in which case I'm, I do:

    junitxml = JUnitXml.fromfile("junit-testsuites.xml")
   # or junitxml = JUnitXml.fromfile("junit-testsuite.xml") without test suiteS element
    # Analyse the type of the root element
    instance_type = type(junitxml).__name__

Then depending on whether instance_type is JUnitXml or TestSuite, I'll parse differently.

Is this the proper way of dealing with the JUnit XML file root element variance when using junitparser module?

thanks.

EnricoMi commented 2 years ago

Alternative is to check junitxml._tag. I do:

suites = [suite for suite in (junitxml if junitxml._tag == "testsuites" else [junitxml])]

Junitparser could always return a TestSuites, even if the file itself contains a TestSuite as root.

Technically, this wouldn't even be a breaking change, but it should be considered one as behaviour for the same file changes.

guilhem-martin commented 2 years ago

Thanks @EnricoMi , looks elegant.

EnricoMi commented 2 years ago

@weiwei what do you think about Junitparser always returning a TestSuites?

weiwei commented 11 months ago

Frankly I'm not sure. I think it eases things for me a bit? I'm open to suggestions though.

weiwei commented 11 months ago

Closing because this is rather old. But if needed we can reopen and discuss again.

jcbsv commented 9 months ago

what do you think about Junitparser always returning a TestSuites?

IMHO it should always return a TestSuites object. Forcing the user to examine the returned object is not optimal.

jcbsv commented 9 months ago

Alternative is to check junitxml._tag. I do:

suites = [suite for suite in (junitxml if junitxml._tag == "testsuites" else [junitxml])]

This should be sufficient:

suites = junitxml if junitxml._tag == "testsuites" else [junitxml]