11"""
22Benchmark test for CLI startup time and evaluation_test import time.
33
4- These tests ensure startup times stay under target thresholds .
5- Run with: pytest tests/test_cli_startup_benchmark.py -v
4+ These are smoke tests that run on schedule (not on every PR) to catch performance regressions .
5+ Run manually with: RUN_BENCHMARK_TESTS=1 pytest tests/test_cli_startup_benchmark.py -v
66"""
77
8+ import os
89import subprocess
910import sys
1011import time
1112
1213import pytest
1314
15+ # Skip benchmark tests unless explicitly enabled via environment variable
16+ # This prevents flaky failures from blocking PRs
17+ SKIP_BENCHMARK = os .environ .get ("RUN_BENCHMARK_TESTS" , "0" ) != "1"
18+ SKIP_REASON = "Benchmark tests only run when RUN_BENCHMARK_TESTS=1 (scheduled smoke tests)"
19+
1420# Target: CLI should start in under 1.5 seconds (CI runners are slower)
1521CLI_STARTUP_TARGET_SECONDS = 1.5
1622
@@ -28,7 +34,7 @@ def measure_cli_startup_time() -> float:
2834 [sys .executable , "-m" , "eval_protocol.cli" , "--help" ],
2935 capture_output = True ,
3036 text = True ,
31- env = {** dict (__import__ ( "os" ) .environ ), "FIREWORKS_API_KEY" : "benchmark-test-key" },
37+ env = {** dict (os .environ ), "FIREWORKS_API_KEY" : "benchmark-test-key" },
3238 )
3339 elapsed = time .perf_counter () - start
3440
@@ -39,6 +45,7 @@ def measure_cli_startup_time() -> float:
3945
4046
4147@pytest .mark .benchmark
48+ @pytest .mark .skipif (SKIP_BENCHMARK , reason = SKIP_REASON )
4249def test_cli_startup_time ():
4350 """Test that CLI startup time is under the target threshold."""
4451 times = []
@@ -64,6 +71,7 @@ def test_cli_startup_time():
6471
6572
6673@pytest .mark .benchmark
74+ @pytest .mark .skipif (SKIP_BENCHMARK , reason = SKIP_REASON )
6775def test_package_import_time ():
6876 """Test that importing eval_protocol package is fast (lazy loading check)."""
6977 # Use subprocess to get a clean import measurement
@@ -90,6 +98,7 @@ def test_package_import_time():
9098
9199
92100@pytest .mark .benchmark
101+ @pytest .mark .skipif (SKIP_BENCHMARK , reason = SKIP_REASON )
93102def test_evaluation_test_import_time ():
94103 """Test that importing evaluation_test decorator is under the target threshold."""
95104 code = """
@@ -135,6 +144,7 @@ def test_evaluation_test_import_time():
135144
136145
137146if __name__ == "__main__" :
147+ # When run directly, always execute (ignore SKIP_BENCHMARK)
138148 print ("=== CLI Startup Benchmark ===\n " )
139149
140150 print ("Testing CLI startup time..." )
0 commit comments