first commit
This commit is contained in:
commit
dd50a0d05e
31 files changed
+5299
No files matched your search
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run the proxdomain test suite.
|
||||
|
||||
Mirrors a compact summary (and failure details) into $GITHUB_STEP_SUMMARY when
|
||||
present, and emits ::error:: annotations, so CI failures are readable even when
|
||||
the job log API is unavailable.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
|
||||
def main() -> int:
|
||||
suite = unittest.TestLoader().discover(str(ROOT / "tests"), top_level_dir=str(ROOT))
|
||||
result = unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
total = result.testsRun
|
||||
failures = len(result.failures)
|
||||
errors = len(result.errors)
|
||||
skipped = len(result.skipped)
|
||||
summary = (
|
||||
f"{total} tests, {failures} failures, {errors} errors, {skipped} skipped "
|
||||
f"({'PASS' if result.wasSuccessful() else 'FAIL'})"
|
||||
)
|
||||
print()
|
||||
print(summary)
|
||||
_write_ci_summary(summary, result)
|
||||
return 0 if result.wasSuccessful() else 1
|
||||
|
||||
|
||||
def _write_ci_summary(summary: str, result: unittest.TestResult) -> None:
|
||||
for test, trace in result.failures + result.errors:
|
||||
label = test.id().split(".")[-1]
|
||||
first_line = next(
|
||||
(line for line in reversed(trace.strip().splitlines()) if line.strip()), "failed"
|
||||
)
|
||||
print(f"::error title={label}::{first_line}")
|
||||
|
||||
path = os.environ.get("GITHUB_STEP_SUMMARY")
|
||||
if not path:
|
||||
return
|
||||
try:
|
||||
with open(path, "a", encoding="utf-8") as handle:
|
||||
handle.write("## proxdomain tests\n\n")
|
||||
handle.write(f"`{summary}`\n\n")
|
||||
for test, trace in result.failures + result.errors:
|
||||
handle.write(f"### {test.id()}\n\n```text\n{trace.strip()}\n```\n\n")
|
||||
except OSError as exc: # pragma: no cover - CI convenience only
|
||||
print(f"warning: cannot write step summary: {exc}", file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user