1616if TYPE_CHECKING :
1717 from codeflash .models .models import BenchmarkKey
1818
19- IS_PYTEST_BENCHMARK_INSTALLED = importlib .util .find_spec ("pytest_benchmark" ) is not None
19+ PYTEST_BENCHMARK_INSTALLED = importlib .util .find_spec ("pytest_benchmark" ) is not None
2020
2121
2222class CodeFlashBenchmarkPlugin :
@@ -251,8 +251,12 @@ def wrapped_func(*args, **kwargs): # noqa: ANN002, ANN003, ANN202
251251
252252 def _run_benchmark (self , func , * args , ** kwargs ): # noqa: ANN001, ANN002, ANN003, ANN202
253253 """Actual benchmark implementation."""
254+ node_path = getattr (self .request .node , "path" , None ) or getattr (self .request .node , "fspath" , None )
255+ if node_path is None :
256+ raise RuntimeError ("Unable to determine test file path from pytest node" )
257+
254258 benchmark_module_path = module_name_from_file_path (
255- Path (str (self . request . node . fspath )), Path (codeflash_benchmark_plugin .project_root ), traverse_up = True
259+ Path (str (node_path )), Path (codeflash_benchmark_plugin .project_root ), traverse_up = True
256260 )
257261
258262 benchmark_function_name = self .request .node .name
@@ -284,24 +288,17 @@ def _run_benchmark(self, func, *args, **kwargs): # noqa: ANN001, ANN002, ANN003
284288codeflash_benchmark_plugin = CodeFlashBenchmarkPlugin ()
285289
286290
287- def pytest_configure (config : pytest .Config ) -> None :
288- """Register the benchmark marker and disable conflicting plugins."""
289- config .addinivalue_line ("markers" , "benchmark: mark test as a benchmark that should be run with codeflash tracing" )
290-
291- if config .getoption ("--codeflash-trace" ) and IS_PYTEST_BENCHMARK_INSTALLED :
292- config .option .benchmark_disable = True
293- config .pluginmanager .set_blocked ("pytest_benchmark" )
294- config .pluginmanager .set_blocked ("pytest-benchmark" )
295-
291+ # def pytest_configure(config: pytest.Config) -> None:
292+ # """Register the benchmark marker and disable conflicting plugins."""
293+ # config.addinivalue_line("markers", "benchmark: mark test as a benchmark that should be run with codeflash tracing")
296294
297- def pytest_addoption ( parser : pytest . Parser ) -> None :
298- parser . addoption (
299- "--codeflash-trace" , action = "store_true" , default = False , help = "Enable CodeFlash tracing for benchmarks"
300- )
295+ # if config.getoption("--codeflash-trace") and PYTEST_BENCHMARK_INSTALLED :
296+ # config.option.benchmark_disable = True
297+ # config.pluginmanager.set_blocked("pytest_benchmark")
298+ # config.pluginmanager.set_blocked("pytest-benchmark" )
301299
302300
303- @pytest .fixture
304- def benchmark (request : pytest .FixtureRequest ) -> object :
305- if not request .config .getoption ("--codeflash-trace" ):
306- return lambda func , * args , ** kwargs : func (* args , ** kwargs )
307- return codeflash_benchmark_plugin .Benchmark (request )
301+ # def pytest_addoption(parser: pytest.Parser) -> None:
302+ # parser.addoption(
303+ # "--codeflash-trace", action="store_true", default=False, help="Enable CodeFlash tracing for benchmarks"
304+ # )
0 commit comments