From 061699b38f9527336aa118cd50467583f39c6646 Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Mon, 18 Mar 2024 19:05:09 -0400 Subject: [PATCH 1/3] feat: support pytest 8.1.1 --- .github/workflows/ci.yml | 12 +++++++++--- src/pytest_codspeed/plugin.py | 12 ++++++++---- tests/test_pytest_plugin.py | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25b11c8..0b10086 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,12 +33,18 @@ jobs: - pytest-benchmark - valgrind python-version: - - "3.7" - "3.8" - "3.9" - "3.10" - "3.11" - "3.12" + pytest-version: + - ">=8.1.1" + include: + - config: pytest-benchmark + python-version: "3.7" + pytest-version: "<8.1.1" + steps: - uses: actions/checkout@v4 @@ -49,8 +55,8 @@ jobs: - if: matrix.config == 'valgrind' || matrix.config == 'pytest-benchmark' name: Install valgrind run: sudo apt-get install valgrind -y - - name: Install dependencies - run: pip install .[dev,compat] + - name: Install dependencies with pytest${{ matrix.pytest-version }} + run: pip install .[dev,compat] "pytest${{ matrix.pytest-version }}" - if: matrix.config != 'pytest-benchmark' name: Uninstall pytest-benchmark run: pip uninstall -y pytest-benchmark diff --git a/src/pytest_codspeed/plugin.py b/src/pytest_codspeed/plugin.py index 13d8e97..559066f 100644 --- a/src/pytest_codspeed/plugin.py +++ b/src/pytest_codspeed/plugin.py @@ -28,6 +28,7 @@ IS_PYTEST_BENCHMARK_INSTALLED = pkgutil.find_loader("pytest_benchmark") is not None SUPPORTS_PERF_TRAMPOLINE = sys.version_info >= (3, 12) +BEFORE_PYTEST_8_1_1 = pytest.version_tuple < (8, 1, 1) @pytest.hookimpl(trylast=True) @@ -95,15 +96,18 @@ def pytest_plugin_registered(plugin, manager: "pytest.PytestPluginManager"): codspeed_plugin: CodSpeedPlugin = manager.get_plugin(PLUGIN_NAME) if codspeed_plugin.is_codspeed_enabled: codspeed_benchmark_fixtures = plugin.getfixturedefs( - "codspeed_benchmark", "" + "codspeed_benchmark", + fixture_manager.session.nodeid + if BEFORE_PYTEST_8_1_1 + else fixture_manager.session, ) assert codspeed_benchmark_fixtures is not None + # Archive the pytest-benchmark fixture fixture_manager._arg2fixturedefs[ "__benchmark" ] = fixture_manager._arg2fixturedefs["benchmark"] - fixture_manager._arg2fixturedefs["benchmark"] = list( - codspeed_benchmark_fixtures - ) + # Replace the pytest-benchmark fixture with the codspeed one + fixture_manager._arg2fixturedefs["benchmark"] = codspeed_benchmark_fixtures @pytest.hookimpl(trylast=True) diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index ce83032..2997f08 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -142,7 +142,7 @@ class TestGroup: def setup_method(self): print(); print("Setup called") - def teardown(self): + def teardown_method(self): print(); print("Teardown called") @pytest.mark.benchmark From e75634be2d9c976393f70a6c5bb3b482da7d813b Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Tue, 19 Mar 2024 17:39:24 -0400 Subject: [PATCH 2/3] chore: switch from black to ruff format --- .pre-commit-config.yaml | 9 +++------ pyproject.toml | 3 ++- src/pytest_codspeed/plugin.py | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f71438..953997a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,15 +8,12 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - - repo: https://github.com/psf/black - rev: 22.3.0 - hooks: - - id: black - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.3.0 hooks: - id: mypy - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.275 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.3 hooks: - id: ruff + - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 8f56f9e..9032d69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ dependencies = [ ] [project.optional-dependencies] -lint = ["black ~= 23.3.0", "isort ~=5.12.0", "mypy ~= 1.3.0", "ruff ~= 0.0.275"] +lint = ["mypy ~= 1.3.0", "ruff ~= 0.3.3"] compat = ["pytest-benchmark ~= 4.0.0", "pytest-xdist ~= 2.0.0"] test = ["pytest ~= 7.0", "pytest-cov ~= 4.0.0"] @@ -73,6 +73,7 @@ python_version = "3.12" [tool.ruff] line-length = 88 +[tool.ruff.lint] select = ["E", "F", "I", "C"] [tool.isort] diff --git a/src/pytest_codspeed/plugin.py b/src/pytest_codspeed/plugin.py index 559066f..24dc656 100644 --- a/src/pytest_codspeed/plugin.py +++ b/src/pytest_codspeed/plugin.py @@ -103,9 +103,9 @@ def pytest_plugin_registered(plugin, manager: "pytest.PytestPluginManager"): ) assert codspeed_benchmark_fixtures is not None # Archive the pytest-benchmark fixture - fixture_manager._arg2fixturedefs[ - "__benchmark" - ] = fixture_manager._arg2fixturedefs["benchmark"] + fixture_manager._arg2fixturedefs["__benchmark"] = ( + fixture_manager._arg2fixturedefs["benchmark"] + ) # Replace the pytest-benchmark fixture with the codspeed one fixture_manager._arg2fixturedefs["benchmark"] = codspeed_benchmark_fixtures From 0d1fdceed60e44941c8cab41fe09b84ddc443b87 Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Tue, 19 Mar 2024 17:44:41 -0400 Subject: [PATCH 3/3] chore: add all-checks job to CI workflow --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b10086..8d13451 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,6 @@ jobs: python-version: "3.7" pytest-version: "<8.1.1" - steps: - uses: actions/checkout@v4 - name: "Set up Python ${{ matrix.python-version }}" @@ -62,3 +61,11 @@ jobs: run: pip uninstall -y pytest-benchmark - name: Run tests run: pytest -vs + + all-checks: + runs-on: ubuntu-latest + steps: + - run: echo "All CI checks passed." + needs: + - static-analysis + - tests