From 501246237290df43b159a255fa61de393e96e80d Mon Sep 17 00:00:00 2001 From: Frank Niessink Date: Wed, 15 Jan 2025 12:57:53 +0100 Subject: [PATCH] Correctly count test suites in JUnit XML files with one root testsuite element. Fixes #10616. --- .../src/source_collectors/junit/test_suites.py | 5 ++++- .../source_collectors/junit/test_test_suites.py | 13 +++++++++++++ docs/src/changelog.md | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/components/collector/src/source_collectors/junit/test_suites.py b/components/collector/src/source_collectors/junit/test_suites.py index eb61a178b8..8c75cc5491 100644 --- a/components/collector/src/source_collectors/junit/test_suites.py +++ b/components/collector/src/source_collectors/junit/test_suites.py @@ -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): diff --git a/components/collector/tests/source_collectors/junit/test_test_suites.py b/components/collector/tests/source_collectors/junit/test_test_suites.py index 7bc3f9993f..c261ccd884 100644 --- a/components/collector/tests/source_collectors/junit/test_test_suites.py +++ b/components/collector/tests/source_collectors/junit/test_test_suites.py @@ -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 = """ + + + + + + """ + 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) diff --git a/docs/src/changelog.md b/docs/src/changelog.md index 9709a0e6fb..e0562edbaf 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -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