weiwei / junitparser

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

implement flavors #108

Closed weiwei closed 1 year ago

weiwei commented 1 year ago

This is to address #101, as well as other frequent xml schema support requirements.

I've thought about JunitXml(flavor='pytest'), but typings will be tricky when it comes to dealing with elements like TestSuite and TestCase, which will also be different with those in the "standard" implementation, For example, autocompletion won't know this TestCase now has a rerun_errors() method.

With implementation in this PR, a flavor and its elements are imported and used separately, and autocompletion works on each case.

from junitparser.flavors.pytest_xml import JUnitXml, TestSuite, TestCase, RerunFailure

# Create cases
case1 = TestCase('case1') # A pytest case
case1.group = 'Group1' # pytest specific
case1.add_rerun_result(RerunFailure('Server Error', '500') # pytest specific

# Create suite and add cases
suite = TestSuite('suite1') # A pytest suite
suite.add_property('build', '55')
suite.add_testcase(case1)
suite.remove_testcase(case2)

# Add suite to JunitXml
xml = JUnitXml() # A pytest JUnitXml class
xml.add_testsuite(suite)
xml.write('junit.xml')

Also address #97 by adding rudimentary types

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.27 :tada:

Comparison is base (314d69c) 97.96% compared to head (284189c) 98.24%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #108 +/- ## ========================================== + Coverage 97.96% 98.24% +0.27% ========================================== Files 6 8 +2 Lines 1231 1424 +193 ========================================== + Hits 1206 1399 +193 Misses 25 25 ``` | [Impacted Files](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei) | Coverage Δ | | |---|---|---| | [junitparser/cli.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-anVuaXRwYXJzZXIvY2xpLnB5) | `50.00% <ø> (ø)` | | | [tests/test\_cli.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-dGVzdHMvdGVzdF9jbGkucHk=) | `100.00% <ø> (ø)` | | | [tests/test\_fromfile.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-dGVzdHMvdGVzdF9mcm9tZmlsZS5weQ==) | `98.75% <ø> (-0.03%)` | :arrow_down: | | [tests/test\_general.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-dGVzdHMvdGVzdF9nZW5lcmFsLnB5) | `99.11% <ø> (-0.01%)` | :arrow_down: | | [junitparser/\_\_init\_\_.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-anVuaXRwYXJzZXIvX19pbml0X18ucHk=) | `100.00% <100.00%> (ø)` | | | [junitparser/junitparser.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-anVuaXRwYXJzZXIvanVuaXRwYXJzZXIucHk=) | `99.12% <100.00%> (ø)` | | | [junitparser/xunit2.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-anVuaXRwYXJzZXIveHVuaXQyLnB5) | `100.00% <100.00%> (ø)` | | | [tests/test\_xunit2.py](https://codecov.io/gh/weiwei/junitparser/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-dGVzdHMvdGVzdF94dW5pdDIucHk=) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.