Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pytest 8.1.1 #28

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ 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
Expand All @@ -49,10 +54,18 @@ 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
- name: Run tests
run: pytest -vs

all-checks:
runs-on: ubuntu-latest
steps:
- run: echo "All CI checks passed."
needs:
- static-analysis
- tests
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -73,6 +73,7 @@ python_version = "3.12"

[tool.ruff]
line-length = 88
[tool.ruff.lint]
select = ["E", "F", "I", "C"]

[tool.isort]
Expand Down
16 changes: 10 additions & 6 deletions src/pytest_codspeed/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
fixture_manager._arg2fixturedefs[
"__benchmark"
] = fixture_manager._arg2fixturedefs["benchmark"]
fixture_manager._arg2fixturedefs["benchmark"] = list(
codspeed_benchmark_fixtures
# Archive the pytest-benchmark fixture
fixture_manager._arg2fixturedefs["__benchmark"] = (
fixture_manager._arg2fixturedefs["benchmark"]
)
# Replace the pytest-benchmark fixture with the codspeed one
fixture_manager._arg2fixturedefs["benchmark"] = codspeed_benchmark_fixtures


@pytest.hookimpl(trylast=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading