From c7fca17faf594bfe242ebe803710b8d355c43b40 Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Tue, 29 Oct 2024 17:33:13 +0100 Subject: [PATCH] fix: fix compatibility with pytest-benchmark 5.0.0 Induced by https://github.com/ionelmc/pytest-benchmark/commit/d6511e3474931feb4e862948128e0c389acfceec --- .github/workflows/ci.yml | 16 +++++++++++----- pyproject.toml | 2 +- src/pytest_codspeed/plugin.py | 12 ++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abd502b..f8ebbf2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,8 @@ jobs: matrix: config: - headless - - pytest-benchmark + - pytest-benchmark-4 + - pytest-benchmark-5 - valgrind python-version: - "3.9" @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 1ee3167..93d8d4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] diff --git a/src/pytest_codspeed/plugin.py b/src/pytest_codspeed/plugin.py index f86e47d..881b27d 100644 --- a/src/pytest_codspeed/plugin.py +++ b/src/pytest_codspeed/plugin.py @@ -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 = {}