Repository navigation
fix: support pytest 9.2 fixture manager changes - #141
claude[bot] wants to merge 3 commits into
Conversation
pytest 9.2 replaced the private `FixtureManager._arg2fixturedefs` with `_arg2node2fixturedefs` (pytest-dev/pytest#14984). The `pytest_plugin_registered` hook wrote into `_arg2fixturedefs` to swap pytest-benchmark's `benchmark` fixture for ours, so every `--codspeed` run with pytest-benchmark installed crashed with an AttributeError. On pytest 9.1+, register the override through the public `pytest.register_fixture` API at session start instead. Older pytest keeps the previous `_arg2fixturedefs` swap. pytest-benchmark itself still reads the removed `Node._nodeid` on pytest 9.2, so the two tests that run it without `--codspeed` are marked as non-strict xfail on that combination. Co-Authored-By: Guillaume Lagrange <19265358+GuillaumeLagrange@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…chmark The matrix only installed the latest pytest, so the fixture override paths for pytest without register_fixture (9.0) and before 8.1.1 were never exercised. Add pytest 9.0 and 8.0 jobs on Python 3.15 only, to avoid the full combinatorial matrix. The valgrind install condition matched a "pytest-benchmark" config that no longer exists since the split into -4 and -5, so the valgrind tests running --codspeed with pytest-benchmark installed were always skipped. Co-Authored-By: Claude <noreply@anthropic.com>
|
@art049 FYI, you're much more familiar with pytest-codspeed than I am |
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryUses
Reviews (1) · Last reviewed commit: "ci: test older pytest versions and run v..." · Reviewed by Greptile |
|
CI is stuck, having a look |
Merging this PR will degrade performance by 1.99%2 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
| if not IS_PYTEST_BENCHMARK_INSTALLED: | ||
| def _benchmark_compat(codspeed_benchmark, request: pytest.FixtureRequest): | ||
| """ | ||
| Compatibility with pytest-benchmark | ||
| """ | ||
| return codspeed_benchmark | ||
|
|
||
| @pytest.fixture(scope="function") | ||
| def benchmark(codspeed_benchmark, request: pytest.FixtureRequest): | ||
| """ | ||
| Compatibility with pytest-benchmark | ||
| """ | ||
| return codspeed_benchmark | ||
|
|
||
| if not IS_PYTEST_BENCHMARK_INSTALLED: | ||
| benchmark = pytest.fixture(scope="function", name="benchmark")(_benchmark_compat) |
Keep the original `benchmark` fixture and `pytest_plugin_registered` hook untouched, and only add the pytest 9.1+ path: the hook returns early when `pytest.register_fixture` is available, and a new `pytest_sessionstart` hook registers the codspeed `benchmark` override at session level instead. Co-Authored-By: Arthur Pastel <15641577+art049@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Requested via Slack thread
Before: with pytest 9.2 and pytest-benchmark installed,
pytest --codspeedcrashes at session start withAttributeError: 'FixtureManager' object has no attribute '_arg2fixturedefs'. pytest 9.2 replaced that private attribute with_arg2node2fixturedefs(pytest-dev/pytest#14984, fixing pytest-dev/pytest#14942), and ourpytest_plugin_registeredhook wrote into it to swap pytest-benchmark'sbenchmarkfixture for ours.After: on pytest 9.1+, codspeed's
benchmarkfixture is registered through the publicpytest.register_fixtureAPI in atrylastpytest_sessionstarthook, at session level, so it takes precedence over the one from pytest-benchmark/pytest-speed.--codspeedruns pass on pytest 9.2.How:
HAS_PYTEST_REGISTER_FIXTURE = hasattr(pytest, "register_fixture")), so it covers 9.1 as well as 9.2 rather than only 9.2. Using the public API wherever it exists means one less private-attribute dependency to break again. If you'd prefer to keep 9.1 on the old path and only switch on 9.2, that's a one-line change to the condition._arg2fixturedefsswap is kept unchanged as the fallback.--codspeed: it reads the removedNode._nodeidinpytest_benchmark/fixture.py(still the case in pytest-benchmark 5.3.0).test_plugin_disabledandtest_pytest_benchmark_compatibilityrun pytest-benchmark without--codspeed, so they are markedxfail(strict=False)only when pytest >= 9.2 and pytest-benchmark are both installed. Non-strict so they start passing again once pytest-benchmark ships a fix. Happy to switch this to a skip, or to drop it if you'd rather keep those jobs red as a reminder.pytest>=8.1.1, which already resolves to 9.2, so CI exercises this path without a matrix change.Tested locally on Python 3.13 with pytest 8.4.2, 9.1.1 and 9.2.0, each with and without pytest-benchmark (plus pytest-benchmark 5.3.0 on 9.2.0).
Generated by Claude Code