diff --git a/testing/ci/summary.py b/testing/ci/summary.py index f23089e..c608fd5 100644 --- a/testing/ci/summary.py +++ b/testing/ci/summary.py @@ -62,18 +62,20 @@ def load_junit_cases(paths: Iterable[Path]) -> list[tuple[str, str]]: root = ET.parse(path).getroot() suites = [root] if root.tag == "testsuite" else list(root.findall("testsuite")) if root.tag == "testsuites" else [] for suite in suites: - for test_case in suite.findall("testcase"): - case_name = (test_case.attrib.get("name") or "").strip() - class_name = (test_case.attrib.get("classname") or "").strip() - if not case_name: + for case in suite.findall("testcase"): + name = (case.attrib.get("name") or "").strip() + classname = (case.attrib.get("classname") or "").strip() + if not name: continue - full_name = f"{class_name}.{case_name}" if class_name else case_name + test_id = f"{classname}::{name}" if classname else name status = "passed" - if test_case.find("failure") is not None or test_case.find("error") is not None: + if case.find("failure") is not None: status = "failed" - elif test_case.find("skipped") is not None: + elif case.find("error") is not None: + status = "error" + elif case.find("skipped") is not None: status = "skipped" - cases.append((full_name, status)) + cases.append((test_id, status)) return cases diff --git a/testing/tests/test_publish_metrics.py b/testing/tests/test_publish_metrics.py index 66925b4..d9e5fec 100644 --- a/testing/tests/test_publish_metrics.py +++ b/testing/tests/test_publish_metrics.py @@ -2,7 +2,7 @@ from __future__ import annotations from pathlib import Path -from testing.ci.summary import RunSummary, load_junit_summary, render_payload +from testing.ci.summary import RunSummary, load_junit_cases, load_junit_summary, render_payload def test_load_junit_summary_combines_suites(tmp_path: Path) -> None: @@ -19,3 +19,29 @@ def test_load_junit_summary_combines_suites(tmp_path: Path) -> None: assert 'bstein_home_quality_gate_tests_total{suite="bstein_home",result="skipped"} 1' in payload assert 'platform_quality_gate_workspace_line_coverage_percent{suite="bstein_home"} 0.000' in payload assert 'platform_quality_gate_source_lines_over_500_total{suite="bstein_home"} 0' in payload + + +def test_load_junit_cases_and_render_test_case_metrics(tmp_path: Path) -> None: + junit = tmp_path / "cases.xml" + junit.write_text( + ( + "" + '' + '' + "" + ), + encoding="utf-8", + ) + + cases = load_junit_cases([junit]) + assert ("app.health::test_ok", "passed") in cases + assert ("app.health::test_fail", "failed") in cases + + payload = render_payload( + suite="bstein_home", + ok=1, + failed=0, + summary=RunSummary(tests=2, failures=1, errors=0, skipped=0), + test_cases=cases, + ) + assert 'platform_quality_gate_test_case_result{suite="bstein_home",test="app.health::test_fail",status="failed"} 1' in payload