Skip to content

Commit a4b204d

Browse files
committed
ready to review
1 parent aa33d77 commit a4b204d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

code_to_optimize/tests/pytest/benchmarks/test_benchmark_bubble_sort.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ def test_sort(benchmark):
77
result = benchmark(sorter, list(reversed(range(500))))
88
assert result == list(range(500))
99

10+
@pytest.mark.benchmark
11+
def test_sort_with_marker(benchmark):
12+
@benchmark
13+
def inner_fn():
14+
return sorter(list(reversed(range(5))))
15+
assert 1==1
16+
1017
# This should not be picked up as a benchmark test
1118
def test_sort2():
1219
result = sorter(list(reversed(range(500))))

codeflash/benchmarking/plugin/custom_plugin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import pytest
44

55

6+
def pytest_configure(config) -> None: # noqa: ANN001
7+
config.addinivalue_line("markers", "benchmark")
8+
9+
610
@pytest.fixture
711
def benchmark(request): # noqa: ANN201, ANN001
812
class CustomBenchmark:
@@ -66,4 +70,8 @@ def extra_info(self): # noqa: ANN202
6670
return request.getfixturevalue("benchmark")
6771
except (pytest.FixtureLookupError, AttributeError):
6872
pass
69-
return CustomBenchmark()
73+
custom_benchmark = CustomBenchmark()
74+
if request.node.get_closest_marker("benchmark"):
75+
# Return our custom benchmark for tests marked with @pytest.mark.benchmark
76+
return custom_benchmark
77+
return custom_benchmark

0 commit comments

Comments
 (0)