Skip to content

Commit

Permalink
Correctly count test suites in JUnit XML files with one root testsuit…
Browse files Browse the repository at this point in the history
…e element.

Fixes #10616.
  • Loading branch information
fniessink committed Jan 15, 2025
1 parent fce8401 commit 5012462
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ async def _parse_source_responses(self, responses: SourceResponses) -> SourceMea
total = 0
for response in responses:
tree = await parse_source_response_xml(response)
test_suites = [tree] if tree.tag == "testsuite" else tree.findall(".//testsuite[testcase]")
if tree.tag == "testsuite" and len(tree.findall("testsuite")) == 0:
test_suites = [tree]
else:
test_suites = tree.findall(".//testsuite[testcase]")
for test_suite in test_suites:
parsed_entity = self.__entity(test_suite)
if self._include_entity(parsed_entity):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ async def test_one_top_level_test_suite(self):
response = await self.collect(get_request_text=xml)
expected_entities = [self.create_entity("ts1", "errored", errored=1)]
self.assert_measurement(response, value="1", total="1", entities=expected_entities)

async def test_one_top_level_nested_test_suite(self):
"""Test that a JUnit XML file with one top level nested test suite works."""
xml = """
<testsuite name="ts1" timestamp="2009-12-19T17:58:59" failures="0" errors="1" skipped="0" tests="1">
<testsuite name="ts1-1" timestamp="2009-12-19T17:58:59" failures="0" errors="1" skipped="0" tests="1">
<testcase name="tc1" classname="cn"><error/></testcase>
</testsuite>
</testsuite>
"""
response = await self.collect(get_request_text=xml)
expected_entities = [self.create_entity("ts1-1", "errored", errored=1)]
self.assert_measurement(response, value="1", total="1", entities=expected_entities)
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ If your currently installed *Quality-time* version is not the latest version, pl

- Don't throw an exception when a Trivy JSON file contains vulnerabilities without fixed version information. Fixes [#10606](https://github.com/ICTU/quality-time/issues/10606).
- When measuring the number of job runs within a time period with Jenkins as source, don't throw an exception when a Jenkins pipeline build has no result yet. Fixes [#10610](https://github.com/ICTU/quality-time/issues/10610).
- Correctly count test suites in JUnit XML files with one root testsuite element. Fixes [#10616](https://github.com/ICTU/quality-time/issues/10616).

### Added

Expand Down

0 comments on commit 5012462

Please sign in to comment.