Save test result to cache for future skip decisions. Records artifact path + mtime and pass/fail result. Called after each test run (success or failure) so the next run can skip re-execution when the artifact is unchanged and the last result was "pass".
(
build_dir: Path, test_name: str, artifact_path: Path, passed: bool
)
| 374 | |
| 375 | |
| 376 | def save_test_result_state( |
| 377 | build_dir: Path, test_name: str, artifact_path: Path, passed: bool |
| 378 | ) -> None: |
| 379 | """Save test result to cache for future skip decisions. |
| 380 | |
| 381 | Records artifact path + mtime and pass/fail result. |
| 382 | Called after each test run (success or failure) so the next run can skip |
| 383 | re-execution when the artifact is unchanged and the last result was "pass". |
| 384 | """ |
| 385 | cache_file = _get_test_result_cache_file(build_dir) |
| 386 | try: |
| 387 | existing: dict = {} |
| 388 | if cache_file.exists(): |
| 389 | try: |
| 390 | with open(cache_file, "r", encoding="utf-8") as f: |
| 391 | existing = json.load(f) |
| 392 | except (json.JSONDecodeError, OSError): |
| 393 | existing = {} |
| 394 | |
| 395 | if artifact_path.exists(): |
| 396 | existing[test_name] = { |
| 397 | "artifact_path": str(artifact_path), |
| 398 | "artifact_mtime": artifact_path.stat().st_mtime, |
| 399 | "result": "pass" if passed else "fail", |
| 400 | } |
| 401 | |
| 402 | with open(cache_file, "w", encoding="utf-8") as f: |
| 403 | json.dump(existing, f) |
| 404 | |
| 405 | except (OSError, json.JSONDecodeError): |
| 406 | pass # Non-critical — next run will fall back to running normally |
| 407 | |
| 408 | |
| 409 | # --------------------------------------------------------------------------- |
no test coverage detected