From 4b927b4be6bafa13cf892e3a0a0b6a678fe7c3e8 Mon Sep 17 00:00:00 2001 From: Frank Niessink Date: Fri, 6 Dec 2024 11:22:57 +0100 Subject: [PATCH] When measuring test cases with Visual Studio TRX as source, search all test category items for test case ids, instead cutting the search short after the first match. Fixes #10460. --- .../collector/src/metric_collectors/test_cases.py | 5 +++-- .../src/source_collectors/visual_studio_trx/tests.py | 9 +++++---- .../source_collectors/visual_studio_trx/base.py | 12 +++++++++--- .../visual_studio_trx/test_tests.py | 2 +- docs/src/changelog.md | 6 ++++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/components/collector/src/metric_collectors/test_cases.py b/components/collector/src/metric_collectors/test_cases.py index 7991afc360..810bd7cbe0 100644 --- a/components/collector/src/metric_collectors/test_cases.py +++ b/components/collector/src/metric_collectors/test_cases.py @@ -59,8 +59,9 @@ class TestCases(MetricCollector): "timeout": "errored", "warning": "errored", } - # Regular expression to identify test case ids in entity attributes: - TEST_CASE_KEY_RE = re.compile(r"\w+\-\d+") + # Regular expression to identify test case ids in entity attributes. Matches identifiers of the form BAR-123, + # while ensuring they are not part of longer identifiers such as FOO-BAR-123 or BAR-123-456: + TEST_CASE_KEY_RE = re.compile(r"(? bool: def __entity(test: Element, result: str, namespaces: Namespaces) -> Entity: """Transform a test case into a test entity.""" name = test.attrib["name"] - for category in test.findall(".//ns:TestCategoryItem", namespaces): - if match := re.search(TestCases.TEST_CASE_KEY_RE, category.attrib["TestCategory"]): - name += f" ({match[0]})" - break + category_items = test.findall(".//ns:TestCategoryItem", namespaces) + categories = [item.attrib["TestCategory"] for item in category_items] + matches = [match[0] for category in categories if (match := re.search(TestCases.TEST_CASE_KEY_RE, category))] + if matches: + name += f" ({', '.join(sorted(matches))})" key = test.attrib["id"] return Entity(key=key, name=name, test_result=result) diff --git a/components/collector/tests/source_collectors/visual_studio_trx/base.py b/components/collector/tests/source_collectors/visual_studio_trx/base.py index 23d8b34061..f8ed68539f 100644 --- a/components/collector/tests/source_collectors/visual_studio_trx/base.py +++ b/components/collector/tests/source_collectors/visual_studio_trx/base.py @@ -41,9 +41,15 @@ class VisualStudioTRXCollectorTestCase(SourceCollectorTestCase): - - - + + + + + + + + + Unreleased" is replaced by the release/release.py script with the new release version and release date. --> +## [Unreleased] + +### Fixed + +- When measuring test cases with Visual Studio TRX as source, search all test category items for test case ids, instead of cutting the search short after the first match. Fixes [#10460](https://github.com/ICTU/quality-time/issues/10460). + ## v5.20.0 - 2024-12-05 ### Added