11from __future__ import annotations
22
3- from typing import Any , Callable
3+ from typing import Callable , Protocol
44
55import pytest
66
77
8- class CodeFlashBenchmarkDummyPlugin :
8+ class GroupProtocol (Protocol ):
9+ """A protocol for objects with a 'name' attribute."""
10+
11+ name : str
12+
13+
14+ class CodeFlashBenchmarkCustomPlugin :
915 @staticmethod
1016 def pytest_plugin_registered (plugin , manager ) -> None : # noqa: ANN001
1117 # Not necessary since run with -p no:benchmark, but just in case
@@ -21,55 +27,57 @@ def pytest_configure(config: pytest.Config) -> None:
2127 )
2228
2329 # Benchmark fixture
24- class DummyBenchmark :
25- """A dummy benchmark object that mimics pytest-benchmark's interface."""
30+ class CustomBenchmark :
31+ """A custom benchmark object that mimics pytest-benchmark's interface."""
2632
2733 def __init__ (self ) -> None :
2834 self .stats = {}
2935
30- def __call__ (self , func : Callable , * args : tuple [ Any , ...], ** kwargs : dict ) -> Any :
36+ def __call__ (self , func : Callable , * args , ** kwargs ): # type: ignore # noqa: ANN002, ANN003, ANN204, PGH003
3137 """Call the function and return its result without benchmarking."""
3238 return func (* args , ** kwargs )
3339
34- def pedantic (
40+ def pedantic ( # noqa: ANN201
3541 self ,
36- target : Callable ,
37- args : tuple = (),
38- kwargs : dict = None ,
39- iterations : int = 1 ,
40- rounds : int = 1 ,
41- warmup_rounds : int = 0 ,
42- setup : Callable = None ,
43- ) -> Any :
42+ target , # noqa: ANN001
43+ args , # noqa: ANN001
44+ kwargs , # noqa: ANN001
45+ iterations : int = 1 , # noqa: ARG002
46+ rounds : int = 1 , # noqa: ARG002
47+ warmup_rounds : int = 0 , # noqa: ARG002
48+ setup = None , # noqa: ANN001
49+ ):
4450 """Mimics the pedantic method of pytest-benchmark."""
51+ if kwargs is None :
52+ kwargs = {}
4553 if setup :
4654 setup ()
4755 if kwargs is None :
4856 kwargs = {}
4957 return target (* args , ** kwargs )
5058
5159 @property
52- def group (self ):
53- """Return a dummy group object."""
54- return type ("Group" , (), {"name" : "dummy " })()
60+ def group (self ) -> GroupProtocol :
61+ """Return a custom group object."""
62+ return type ("Group" , (), {"name" : "custom " })()
5563
5664 @property
57- def name (self ):
58- """Return a dummy name."""
59- return "dummy_benchmark "
65+ def name (self ) -> str :
66+ """Return a custom name."""
67+ return "custom_benchmark "
6068
6169 @property
62- def fullname (self ):
63- """Return a dummy fullname."""
64- return "dummy ::benchmark"
70+ def fullname (self ) -> str :
71+ """Return a custom fullname."""
72+ return "custom ::benchmark"
6573
6674 @property
67- def params (self ):
75+ def params (self ) -> dict :
6876 """Return empty params."""
6977 return {}
7078
7179 @property
72- def extra_info (self ):
80+ def extra_info (self ) -> dict :
7381 """Return empty extra info."""
7482 return {}
7583
@@ -82,7 +90,7 @@ def benchmark(request: pytest.FixtureRequest) -> object:
8290 return request .getfixturevalue ("benchmark" )
8391 except (pytest .FixtureLookupError , AttributeError ):
8492 pass
85- return CodeFlashBenchmarkDummyPlugin . DummyBenchmark (request )
93+ return CodeFlashBenchmarkCustomPlugin . CustomBenchmark (request )
8694
8795
88- codeflash_benchmark_plugin = CodeFlashBenchmarkDummyPlugin ()
96+ codeflash_benchmark_plugin = CodeFlashBenchmarkCustomPlugin ()
0 commit comments