From cdbe74ed892cfeed66ddc3172a10c2a5285456d2 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 17 Dec 2025 08:56:35 -0800 Subject: [PATCH] Return early from CLI startup test when under threshold --- tests/test_cli_startup.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/test_cli_startup.py b/tests/test_cli_startup.py index 43fcc3c..523201b 100644 --- a/tests/test_cli_startup.py +++ b/tests/test_cli_startup.py @@ -19,7 +19,7 @@ def test_cli_startup_time() -> None: cf_path = shutil.which("cf") assert cf_path is not None, "cf command not found in PATH" - # Run multiple times and take the minimum to reduce noise + # Run up to 3 times, return early if we hit the threshold times: list[float] = [] for _ in range(3): start = time.perf_counter() @@ -35,16 +35,18 @@ def test_cli_startup_time() -> None: # Verify the command succeeded assert result.returncode == 0, f"CLI failed: {result.stderr}" - best_time = min(times) - avg_time = sum(times) / len(times) + # Pass early if under threshold + if elapsed < CLI_STARTUP_THRESHOLD: + print(f"\nCLI startup: {elapsed:.3f}s (threshold: {CLI_STARTUP_THRESHOLD}s)") + return - # Always print timing info - visible in CI logs even on failure + # All attempts exceeded threshold + best_time = min(times) msg = ( f"\nCLI startup times: {[f'{t:.3f}s' for t in times]}\n" - f"Best: {best_time:.3f}s, Avg: {avg_time:.3f}s, Threshold: {CLI_STARTUP_THRESHOLD}s" + f"Best: {best_time:.3f}s, Threshold: {CLI_STARTUP_THRESHOLD}s" ) print(msg) - assert best_time < CLI_STARTUP_THRESHOLD, ( - f"CLI startup too slow!\n{msg}\nCheck for slow imports." - ) + err_msg = f"CLI startup too slow!\n{msg}\nCheck for slow imports." + raise AssertionError(err_msg)