Skip to content

Commit

Permalink
fix: fix compatibility with pytest-benchmark 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Oct 29, 2024
1 parent 630a6cd commit c7fca17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
matrix:
config:
- headless
- pytest-benchmark
- pytest-benchmark-4
- pytest-benchmark-5
- valgrind
python-version:
- "3.9"
Expand All @@ -51,10 +52,15 @@ jobs:
name: Install valgrind
run: sudo apt-get install valgrind -y
- name: Install dependencies with pytest${{ matrix.pytest-version }}
run: pip install .[dev,compat,build] "pytest${{ matrix.pytest-version }}"
- if: matrix.config != 'pytest-benchmark'
name: Uninstall pytest-benchmark
run: pip uninstall -y pytest-benchmark
run: |
pip install .[dev,compat,build] "pytest${{ matrix.pytest-version }}"
pip uninstall -y pytest-benchmark
- if: matrix.config == 'pytest-benchmark-4'
name: Install pytest-benchmark 4.0.0
run: pip install pytest-benchmark~=4.0.0
- if: matrix.config == 'pytest-benchmark-5'
name: Install pytest-benchmark 5.0.0
run: pip install pytest-benchmark~=5.0.0
- name: Run tests
run: pytest -vs

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies = [
build = ["semver>=3.0.2"]
lint = ["mypy ~= 1.11.2", "ruff ~= 0.6.5"]
compat = [
"pytest-benchmark ~= 4.0.0",
"pytest-benchmark ~= 5.0.0",
"pytest-xdist ~= 3.6.1",
# "pytest-speed>=0.3.5",
]
Expand Down
12 changes: 12 additions & 0 deletions src/pytest_codspeed/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus):
class BenchmarkFixture:
"""The fixture that can be used to benchmark a function."""

@property # type: ignore
def __class__(self):
# Bypass the pytest-benchmark fixture class check
# https://github.com/ionelmc/pytest-benchmark/commit/d6511e3474931feb4e862948128e0c389acfceec
if IS_PYTEST_BENCHMARK_INSTALLED:
from pytest_benchmark.fixture import (
BenchmarkFixture as PytestBenchmarkFixture,
)

return PytestBenchmarkFixture
return BenchmarkFixture

def __init__(self, request: pytest.FixtureRequest):
self.extra_info: dict = {}

Expand Down

0 comments on commit c7fca17

Please sign in to comment.