88
99PYTEST_BENCHMARK_INSTALLED = importlib .util .find_spec ("pytest_benchmark" ) is not None
1010
11+ benchmark_options = [
12+ ("--benchmark-columns" , "store" , None , "Benchmark columns" ),
13+ ("--benchmark-group-by" , "store" , None , "Benchmark group by" ),
14+ ("--benchmark-name" , "store" , None , "Benchmark name pattern" ),
15+ ("--benchmark-sort" , "store" , None , "Benchmark sort column" ),
16+ ("--benchmark-json" , "store" , None , "Benchmark JSON output file" ),
17+ ("--benchmark-save" , "store" , None , "Benchmark save name" ),
18+ ("--benchmark-warmup" , "store" , None , "Benchmark warmup" ),
19+ ("--benchmark-warmup-iterations" , "store" , None , "Benchmark warmup iterations" ),
20+ ("--benchmark-min-time" , "store" , None , "Benchmark minimum time" ),
21+ ("--benchmark-max-time" , "store" , None , "Benchmark maximum time" ),
22+ ("--benchmark-min-rounds" , "store" , None , "Benchmark minimum rounds" ),
23+ ("--benchmark-timer" , "store" , None , "Benchmark timer" ),
24+ ("--benchmark-calibration-precision" , "store" , None , "Benchmark calibration precision" ),
25+ ("--benchmark-disable" , "store_true" , False , "Disable benchmarks" ),
26+ ("--benchmark-skip" , "store_true" , False , "Skip benchmarks" ),
27+ ("--benchmark-only" , "store_true" , False , "Only run benchmarks" ),
28+ ("--benchmark-verbose" , "store_true" , False , "Verbose benchmark output" ),
29+ ("--benchmark-histogram" , "store" , None , "Benchmark histogram" ),
30+ ("--benchmark-compare" , "store" , None , "Benchmark compare" ),
31+ ("--benchmark-compare-fail" , "store" , None , "Benchmark compare fail threshold" ),
32+ ]
33+
1134
1235def pytest_configure (config : pytest .Config ) -> None :
1336 """Register the benchmark marker and disable conflicting plugins."""
1437 config .addinivalue_line ("markers" , "benchmark: mark test as a benchmark that should be run with codeflash tracing" )
1538
16- if config .getoption ("--codeflash-trace" ) and PYTEST_BENCHMARK_INSTALLED :
17- config .option .benchmark_disable = True
18- config .pluginmanager .set_blocked ("pytest_benchmark" )
19- config .pluginmanager .set_blocked ("pytest-benchmark" )
39+ if config .getoption ("--codeflash-trace" ):
40+ # When --codeflash-trace is used, ignore all benchmark options by resetting them to defaults
41+ for option , _ , default , _ in benchmark_options :
42+ option_name = option .replace ("--" , "" ).replace ("-" , "_" )
43+ if hasattr (config .option , option_name ):
44+ setattr (config .option , option_name , default )
45+
46+ if PYTEST_BENCHMARK_INSTALLED :
47+ config .pluginmanager .set_blocked ("pytest_benchmark" )
48+ config .pluginmanager .set_blocked ("pytest-benchmark" )
2049
2150
2251def pytest_addoption (parser : pytest .Parser ) -> None :
2352 parser .addoption (
2453 "--codeflash-trace" , action = "store_true" , default = False , help = "Enable CodeFlash tracing for benchmarks"
2554 )
55+ # These options are ignored when --codeflash-trace is used
56+ for option , action , default , help_text in benchmark_options :
57+ help_suffix = " (ignored when --codeflash-trace is used)"
58+ parser .addoption (option , action = action , default = default , help = help_text + help_suffix )
2659
2760
2861@pytest .fixture
@@ -37,7 +70,7 @@ def benchmark(request: pytest.FixtureRequest) -> object:
3770 # If pytest-benchmark is installed and --codeflash-trace is not enabled,
3871 # return the normal pytest-benchmark fixture
3972 if PYTEST_BENCHMARK_INSTALLED :
40- from pytest_benchmark .fixture import BenchmarkFixture as BSF # noqa: N814
73+ from pytest_benchmark .fixture import BenchmarkFixture as BSF # pyright: ignore[reportMissingImports] # noqa: I001, N814
4174
4275 bs = getattr (config , "_benchmarksession" , None )
4376 if bs and bs .skip :
0 commit comments