Skip to content

Commit c7fca17

Browse files
committed
fix: fix compatibility with pytest-benchmark 5.0.0
Induced by ionelmc/pytest-benchmark@d6511e3
1 parent 630a6cd commit c7fca17

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ jobs:
3030
matrix:
3131
config:
3232
- headless
33-
- pytest-benchmark
33+
- pytest-benchmark-4
34+
- pytest-benchmark-5
3435
- valgrind
3536
python-version:
3637
- "3.9"
@@ -51,10 +52,15 @@ jobs:
5152
name: Install valgrind
5253
run: sudo apt-get install valgrind -y
5354
- name: Install dependencies with pytest${{ matrix.pytest-version }}
54-
run: pip install .[dev,compat,build] "pytest${{ matrix.pytest-version }}"
55-
- if: matrix.config != 'pytest-benchmark'
56-
name: Uninstall pytest-benchmark
57-
run: pip uninstall -y pytest-benchmark
55+
run: |
56+
pip install .[dev,compat,build] "pytest${{ matrix.pytest-version }}"
57+
pip uninstall -y pytest-benchmark
58+
- if: matrix.config == 'pytest-benchmark-4'
59+
name: Install pytest-benchmark 4.0.0
60+
run: pip install pytest-benchmark~=4.0.0
61+
- if: matrix.config == 'pytest-benchmark-5'
62+
name: Install pytest-benchmark 5.0.0
63+
run: pip install pytest-benchmark~=5.0.0
5864
- name: Run tests
5965
run: pytest -vs
6066

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies = [
4848
build = ["semver>=3.0.2"]
4949
lint = ["mypy ~= 1.11.2", "ruff ~= 0.6.5"]
5050
compat = [
51-
"pytest-benchmark ~= 4.0.0",
51+
"pytest-benchmark ~= 5.0.0",
5252
"pytest-xdist ~= 3.6.1",
5353
# "pytest-speed>=0.3.5",
5454
]

src/pytest_codspeed/plugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus):
320320
class BenchmarkFixture:
321321
"""The fixture that can be used to benchmark a function."""
322322

323+
@property # type: ignore
324+
def __class__(self):
325+
# Bypass the pytest-benchmark fixture class check
326+
# https://github.com/ionelmc/pytest-benchmark/commit/d6511e3474931feb4e862948128e0c389acfceec
327+
if IS_PYTEST_BENCHMARK_INSTALLED:
328+
from pytest_benchmark.fixture import (
329+
BenchmarkFixture as PytestBenchmarkFixture,
330+
)
331+
332+
return PytestBenchmarkFixture
333+
return BenchmarkFixture
334+
323335
def __init__(self, request: pytest.FixtureRequest):
324336
self.extra_info: dict = {}
325337

0 commit comments

Comments
 (0)