Skip to content

Commit bf98531

Browse files
authored
Ignore multiple elements for the same test in JUnit XML report (#4364)
Fixes #4331. --------- Signed-off-by: Pavel Chekin <pavel.chekin@intel.com>
1 parent 26db8ad commit bf98531

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

scripts/pass_rate.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,19 @@ def parse_report(report_path: pathlib.Path) -> ReportStats:
8484
"""Parses the specified report."""
8585
stats = ReportStats(name=report_path.stem)
8686
root = parse(report_path).getroot()
87-
testsuite_fixme_tests = set()
87+
all_tests = set()
88+
fixme_tests = set()
8889

8990
for testsuite in root:
9091
for testcase in testsuite.iter('testcase'):
92+
name = f'{testcase.get("classname")}::{testcase.get("name")}'
93+
94+
# ignore multiple elements for the same test
95+
if name in all_tests:
96+
continue
9197
stats.total += 1
98+
all_tests.add(name)
99+
92100
if testcase.find('failure') is not None or testcase.find('error') is not None:
93101
stats.failed += 1
94102
continue
@@ -102,8 +110,8 @@ def parse_report(report_path: pathlib.Path) -> ReportStats:
102110

103111
for warning in get_warnings(report_path.parent, report_path.stem):
104112
if 'FIXME' in warning.message:
105-
testsuite_fixme_tests.add(warning.location)
106-
stats.fixme += len(testsuite_fixme_tests)
113+
fixme_tests.add(warning.location)
114+
stats.fixme += len(fixme_tests)
107115

108116
stats.passed = stats.total - stats.failed - stats.skipped - stats.xfailed
109117
return stats

scripts/test_pass_rate.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Real JUnit report with the 3 tests. One test passed, but there is an error at test teardown.
2626
# Note that pytest incorrectly reports 4 tests instead of 3.
2727
# https://github.com/intel/intel-xpu-backend-for-triton/issues/4341.
28-
JUNIT_XML_REPORT = """\
28+
JUNIT_XML_REPORT1 = """\
2929
<?xml version="1.0" encoding="utf-8"?>
3030
<testsuites>
3131
<testsuite name="pytest" errors="1" failures="0" skipped="2" tests="4" time="31.615" timestamp="2025-05-28T15:26:42.685704+00:00" hostname="example">
@@ -36,6 +36,22 @@
3636
</testsuites>
3737
"""
3838

39+
# JUnit report with the same test reported twice: one for test failure, another for error at teardown
40+
# https://github.com/intel/intel-xpu-backend-for-triton/issues/4331.
41+
JUNIT_XML_REPORT2 = """\
42+
<?xml version="1.0" encoding="utf-8"?>
43+
<testsuites>
44+
<testsuite>
45+
<testcase classname="python.test.unit.runtime.test_compilation_listener" name="test_compile_stats">
46+
<failure/>
47+
</testcase>
48+
<testcase classname="python.test.unit.runtime.test_compilation_listener" name="test_compile_stats">
49+
<error/>
50+
</testcase>
51+
</testsuite>
52+
</testsuites>
53+
"""
54+
3955

4056
def test_get_warnings_empty_file(tmp_path):
4157
warnings_path = tmp_path / 'suite-warnings.json'
@@ -86,12 +102,23 @@ def test_generate_junit_report(tmp_path):
86102
assert stats[0].total == 3
87103

88104

89-
def test_parse_report(tmp_path):
105+
def test_parse_report_ignore_tests_attribute(tmp_path):
90106
report_path = tmp_path / 'suite.xml'
91-
report_path.write_text(JUNIT_XML_REPORT)
107+
report_path.write_text(JUNIT_XML_REPORT1)
92108
stats = pass_rate.parse_report(report_path)
93109
assert stats.passed == 0
94110
assert stats.xfailed == 2
95111
assert stats.failed == 1
96112
assert stats.skipped == 0
97113
assert stats.total == 3
114+
115+
116+
def test_parse_report_duplicate_test(tmp_path):
117+
report_path = tmp_path / 'suite.xml'
118+
report_path.write_text(JUNIT_XML_REPORT2)
119+
stats = pass_rate.parse_report(report_path)
120+
assert stats.passed == 0
121+
assert stats.xfailed == 0
122+
assert stats.failed == 1
123+
assert stats.skipped == 0
124+
assert stats.total == 1

0 commit comments

Comments
 (0)