|
3 | 3 | import pkgutil |
4 | 4 | import sys |
5 | 5 | from dataclasses import dataclass, field |
6 | | -from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Union |
| 6 | +from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union |
7 | 7 |
|
8 | 8 | import pytest |
9 | 9 | from _pytest.fixtures import FixtureManager |
@@ -230,21 +230,27 @@ def pytest_runtest_protocol(item: "pytest.Item", nextitem: Union["pytest.Item", |
230 | 230 | return reports # Deny further protocol hooks execution |
231 | 231 |
|
232 | 232 |
|
233 | | -@pytest.fixture(scope="function") |
234 | | -def codspeed_benchmark(request: "pytest.FixtureRequest") -> Callable: |
235 | | - plugin = get_plugin(request.config) |
| 233 | +class BenchmarkFixture: |
| 234 | + def __init__(self, request: "pytest.FixtureRequest"): |
| 235 | + self.extra_info: Dict = {} |
| 236 | + |
| 237 | + self._request = request |
236 | 238 |
|
237 | | - def run(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: |
| 239 | + def __call__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: |
| 240 | + plugin = get_plugin(self._request.config) |
238 | 241 | plugin.benchmark_count += 1 |
239 | 242 | if plugin.is_codspeed_enabled and plugin.should_measure: |
240 | 243 | assert plugin.lib is not None |
241 | 244 | _run_with_instrumentation( |
242 | | - plugin.lib, request.node.nodeid, func, *args, **kwargs |
| 245 | + plugin.lib, self._request.node.nodeid, func, *args, **kwargs |
243 | 246 | ) |
244 | 247 | else: |
245 | 248 | func(*args, **kwargs) |
246 | 249 |
|
247 | | - return run |
| 250 | + |
| 251 | +@pytest.fixture(scope="function") |
| 252 | +def codspeed_benchmark(request: "pytest.FixtureRequest") -> Callable: |
| 253 | + return BenchmarkFixture(request) |
248 | 254 |
|
249 | 255 |
|
250 | 256 | if not IS_PYTEST_BENCHMARK_INSTALLED: |
|
0 commit comments