Skip to content

Commit 83345de

Browse files
authored
Fix the total number of tests in pass_rate.py (#4343)
PyTest JUnit XML report contains incorrect number of total tests if test is passed but there is an error at teardown. Fixes #4341. Signed-off-by: Pavel Chekin <[email protected]>
1 parent 9d1fcc4 commit 83345de

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

scripts/pass_rate.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,26 @@ 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()
88+
8789
for testsuite in root:
88-
testsuite_fixme_tests = set()
89-
stats.total += int(testsuite.get('tests'))
90-
for skipped in testsuite.iter('skipped'):
90+
for testcase in testsuite.iter('testcase'):
91+
stats.total += 1
92+
if testcase.find('failure') is not None or testcase.find('error') is not None:
93+
stats.failed += 1
94+
continue
95+
skipped = testcase.find('skipped')
96+
if skipped is None:
97+
continue
9198
if skipped.get('type') == 'pytest.skip':
9299
stats.skipped += 1
93100
elif skipped.get('type') == 'pytest.xfail':
94101
stats.xfailed += 1
95-
for _ in testsuite.iter('failure'):
96-
stats.failed += 1
97-
for _ in testsuite.iter('error'):
98-
stats.failed += 1
99-
for warning in get_warnings(report_path.parent, report_path.stem):
100-
if 'FIXME' in warning.message:
101-
testsuite_fixme_tests.add(warning.location)
102-
stats.fixme += len(testsuite_fixme_tests)
102+
103+
for warning in get_warnings(report_path.parent, report_path.stem):
104+
if 'FIXME' in warning.message:
105+
testsuite_fixme_tests.add(warning.location)
106+
stats.fixme += len(testsuite_fixme_tests)
103107

104108
stats.passed = stats.total - stats.failed - stats.skipped - stats.xfailed
105109
return stats

scripts/test_pass_rate.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
- test22
2323
"""
2424

25+
# Real JUnit report with the 3 tests. One test passed, but there is an error at test teardown.
26+
# Note that pytest incorrectly reports 4 tests instead of 3.
27+
# https://github.com/intel/intel-xpu-backend-for-triton/issues/4341.
28+
JUNIT_XML_REPORT = """\
29+
<?xml version="1.0" encoding="utf-8"?>
30+
<testsuites>
31+
<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">
32+
<testcase classname="python.test.unit.test_perf_warning" name="test_remark_swp_op_before_operands" time="17.602"><error message="xxx"></error></testcase>
33+
<testcase classname="python.test.unit.test_perf_warning" name="test_mma_remark" time="0.019"><skipped type="pytest.xfail" message="Not designed for XPU" /></testcase>
34+
<testcase classname="python.test.unit.test_perf_warning" name="test_remark_vectorization" time="0.030"><skipped type="pytest.xfail" message="Not designed for XPU" /></testcase>
35+
</testsuite>
36+
</testsuites>
37+
"""
38+
2539

2640
def test_get_warnings_empty_file(tmp_path):
2741
warnings_path = tmp_path / 'suite-warnings.json'
@@ -70,3 +84,14 @@ def test_generate_junit_report(tmp_path):
7084
assert stats[0].failed == 1
7185
assert stats[0].skipped == 1
7286
assert stats[0].total == 3
87+
88+
89+
def test_parse_report(tmp_path):
90+
report_path = tmp_path / 'suite.xml'
91+
report_path.write_text(JUNIT_XML_REPORT)
92+
stats = pass_rate.parse_report(report_path)
93+
assert stats.passed == 0
94+
assert stats.xfailed == 2
95+
assert stats.failed == 1
96+
assert stats.skipped == 0
97+
assert stats.total == 3

0 commit comments

Comments
 (0)