weiwei / junitparser

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

junitparser.py: Fix removing items with xml.etree #102

Closed carlescufi closed 2 years ago

carlescufi commented 2 years ago

The iteration in TestCase.result.setter did not work properly when using xml.etree instead of lxml.etree. This was because the Element.remove() method was being invoked while iterating the elements, and apparently xml.etree does not support that. Instead, use a prepopulated lits of Elements to iterate and remove.

Fixes #99.

Signed-off-by: Carles Cufi carles.cufi@nordicsemi.no

carlescufi commented 2 years ago

@weiwei FYI

EnricoMi commented 2 years ago

I think it would be worth adding a unit test that fails with lxml. This reduces the risk that someone optimizes this fix away as it seems redundant.

carlescufi commented 2 years ago

I think it would be worth adding a unit test that fails with lxml. This reduces the risk that someone optimizes this fix away as it seems redundant.

Thanks for the feedback! Not sure I get it. This never failed with lxml, only with xml. With this patch it doesn't fail with either. So not sure what the unit test would check?

EnricoMi commented 2 years ago

Well, then the unit test should check that it does not fail (well work correctly) for either, so that the test fails if someone undoes the fix.

carlescufi commented 2 years ago

Well, then the unit test should check that it does not fail (well work correctly) for either, so that the test fails if someone undoes the fix.

OK, I'll try to come up with a unit test for this.

carlescufi commented 2 years ago

@EnricoMi I added a unit test for this, as well as fixing an existing one. I verified that it fails when lxml is not installed and the first commit in this PR is not applied. Together with #103, this should ensure that we test this with both XML implementations.

codecov[bot] commented 2 years ago

Codecov Report

Base: 98.36% // Head: 98.38% // Increases project coverage by +0.02% :tada:

Coverage data is based on head (8124c97) compared to base (af4f061). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #102 +/- ## ========================================== + Coverage 98.36% 98.38% +0.02% ========================================== Files 6 6 Lines 1220 1238 +18 ========================================== + Hits 1200 1218 +18 Misses 20 20 ``` | [Impacted Files](https://codecov.io/gh/weiwei/junitparser/pull/102?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei) | Coverage Δ | | |---|---|---| | [junitparser/junitparser.py](https://codecov.io/gh/weiwei/junitparser/pull/102/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-anVuaXRwYXJzZXIvanVuaXRwYXJzZXIucHk=) | `99.14% <100.00%> (ø)` | | | [tests/test\_general.py](https://codecov.io/gh/weiwei/junitparser/pull/102/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Wang+Weiwei#diff-dGVzdHMvdGVzdF9nZW5lcmFsLnB5) | `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 at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

weiwei commented 2 years ago

@carlescufi Thanks for the PR!

carlescufi commented 2 years ago

@carlescufi Thanks for the PR!

No problem! Thanks for merging!