diff --git a/codeflash/benchmarking/plugin/plugin.py b/codeflash/benchmarking/plugin/plugin.py index a120a9496..a45974209 100644 --- a/codeflash/benchmarking/plugin/plugin.py +++ b/codeflash/benchmarking/plugin/plugin.py @@ -233,12 +233,16 @@ def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item if not config.getoption("--codeflash-trace"): return + skip_marker = pytest.mark.skip(reason="Test requires benchmark marker") for item in items: # Check for @pytest.mark.benchmark marker - if hasattr(item, "get_closest_marker"): - marker = item.get_closest_marker("benchmark") - if marker is None: - item.add_marker(pytest.mark.skip(reason="Test requires benchmark marker")) + get_marker = getattr(item, "get_closest_marker", None) + if get_marker is not None: + if get_marker("benchmark") is None: + item.add_marker(skip_marker) + else: + # If item does not have get_closest_marker (rare), skip it for correctness + continue # Benchmark fixture class Benchmark: # noqa: D106