|
12 | 12 | from codeflash.benchmarking.codeflash_trace import codeflash_trace |
13 | 13 | from codeflash.code_utils.code_utils import module_name_from_file_path |
14 | 14 |
|
15 | | -# from codeflash.models.models import BenchmarkKey |
16 | 15 |
|
17 | | - |
18 | | -@dataclass |
| 16 | +@dataclass(frozen=True) |
19 | 17 | class BenchmarkKey: |
20 | 18 | module_path: str |
21 | 19 | function_name: str |
@@ -192,6 +190,7 @@ def get_benchmark_timings(trace_path: Path) -> dict[BenchmarkKey, int]: |
192 | 190 |
|
193 | 191 | # Create the benchmark key (file::function::line) |
194 | 192 | benchmark_key = BenchmarkKey(module_path=benchmark_file, function_name=benchmark_func) |
| 193 | + print(f"XXX Processing benchmark: {benchmark_key}") |
195 | 194 | # Subtract overhead from total time |
196 | 195 | overhead = overhead_by_benchmark.get(benchmark_key, 0) |
197 | 196 | result[benchmark_key] = time_ns - overhead |
@@ -232,26 +231,16 @@ def pytest_configure(config: pytest.Config) -> None: |
232 | 231 |
|
233 | 232 | @staticmethod |
234 | 233 | def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None: |
235 | | - # Skip tests that don't have the benchmark fixture |
| 234 | + # Skip tests that don't have the benchmark marker |
236 | 235 | if not config.getoption("--codeflash-trace"): |
237 | 236 | return |
238 | 237 |
|
239 | | - skip_no_benchmark = pytest.mark.skip(reason="Test requires benchmark fixture") |
240 | 238 | for item in items: |
241 | | - # Check for direct benchmark fixture usage |
242 | | - has_fixture = hasattr(item, "fixturenames") and "benchmark" in item.fixturenames |
243 | | - |
244 | 239 | # Check for @pytest.mark.benchmark marker |
245 | | - has_marker = False |
246 | 240 | if hasattr(item, "get_closest_marker"): |
247 | 241 | marker = item.get_closest_marker("benchmark") |
248 | | - if marker is not None: |
249 | | - has_marker = True |
250 | | - print("XXX FOUND THE BENCHMARK MARKER") |
251 | | - |
252 | | - # Skip if neither fixture nor marker is present |
253 | | - if not (has_fixture or has_marker): |
254 | | - item.add_marker(skip_no_benchmark) |
| 242 | + if marker is None: |
| 243 | + item.add_marker(pytest.mark.skip(reason="Test requires benchmark marker")) |
255 | 244 |
|
256 | 245 | # Benchmark fixture |
257 | 246 | class Benchmark: # noqa: D106 |
@@ -307,11 +296,10 @@ def _run_benchmark(self, func, *args, **kwargs): # noqa: ANN001, ANN002, ANN003 |
307 | 296 | @staticmethod |
308 | 297 | @pytest.fixture |
309 | 298 | def benchmark(request: pytest.FixtureRequest) -> object: |
| 299 | + """Fixture to provide the benchmark functionality.""" |
310 | 300 | if not request.config.getoption("--codeflash-trace"): |
311 | | - print("XXX NOOOO PLS") |
312 | 301 | return None |
313 | 302 | print("XXX BENCHMARK PLUGIN INITIATED") |
314 | | - |
315 | 303 | return CodeFlashBenchmarkPlugin.Benchmark(request) |
316 | 304 |
|
317 | 305 |
|
|
0 commit comments