ci(bstein-home): publish per-test result metrics

This commit is contained in:
codex 2026-04-20 11:53:59 -03:00
parent 85abe72f62
commit 3d9f449d72
2 changed files with 37 additions and 9 deletions

View File

@ -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

View File

@ -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(
(
"<testsuite>"
'<testcase classname="app.health" name="test_ok" />'
'<testcase classname="app.health" name="test_fail"><failure/></testcase>'
"</testsuite>"
),
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