Skip to content

Rebuild cached fixtures when declared dependency definitions change - #15177

Open
rongali-commits wants to merge 1 commit into
pytest-dev:mainfrom
rongali-commits:codex/fixture-dependency-2844
Open

rongali-commits wants to merge 1 commit into
pytest-dev:mainfrom
rongali-commits:codex/fixture-dependency-2844

Conversation

@rongali-commits

@rongali-commits rongali-commits commented Oct 14, 2026 •

Copy link
Copy Markdown

When two test modules override the same declared dependency, a shared session fixture can keep module A's value while module B requires its own value. This can occur even when the shared fixture's own parameter has not changed.

Record the dependency definitions used to build the cached result and check them before reuse. Rebuild on a changed definition, and guard cleanup callbacks so a previous dependency cannot tear down a replacement generation. Exclude the synthetic request definition, which is created separately per request. Preserve the existing parameter cache-key behaviour.

Fixes #2844.

Ten regression cases cover session/module scope, parametrized/ordinary dependencies, both module orders, repeated reuse, teardown order, stale callbacks, and cached setup errors followed by an override. Six fail against unchanged source; all ten pass with the candidate. The boundary is declared dependencies; this does not attempt general dynamic getfixturevalue tracking.

Validation on Windows:

  • Python 3.12.14 full configured suite: 4600 passed, 160 skipped, 13 xfailed, 1 xpassed, 2 warnings in 654.16s (0:10:54).
  • Python 3.13.16 full configured suite: 4599 passed, 161 skipped, 13 xfailed, 1 xpassed, 2 warnings in 441.96s (0:07:21).
  • All configured repository pre-commit hooks passed.
  • Local manual combination with Respect parametrization scope in fixture cache reuse #15112: eleven targeted cases passed. This is not an entire-PR compatibility claim. Account for changes in fixture dependencies properly #14104 rewrites the touched lifecycle and will require coordination if it lands first.

The full runs use a short temporary path, UTF-8 subprocess output, stable generated metadata, disabled automatic external plugins and Hypothesis explicitly loaded at startup. No test deselections or warning suppression were used. Hosted validation for submitted head 0cf8c08a0a10d47a12890a839e152cf0983844ce is now complete: all 36 reported checks are successful, including Windows, Ubuntu and macOS test jobs, packaging, docs, pre-commit, changelog and coverage checks. Test workflow, PR checks.

Two batches of five paired whole-process comparisons on 3,000-test synthetic workloads:

Workload Original median Candidate median Change
Initial: cached 6.186s 7.908s +27.84%
Initial: mixed 3.640s 3.626s -0.40%
Repeat: cached 3.220s 3.156s -1.98%
Repeat: mixed 4.657s 4.820s +3.50%

The isolated cached-method benchmark was slower by 15–27%; the numbers above measure complete invocations. Large timing variation across and within batches means the whole-process experiment is inconclusive. No performance improvement or zero-cost claim is made. The isolated cost remains a review concern. Public raw measurements and reproduction harnesses are available; a stable benchmark environment may be needed for a precise assessment.

AI assistance: OpenAI Codex helped prepare the implementation and tests. Rongali Chaitanya reviewed the concrete patch and confirmed understanding of dependency invalidation and the stale-finalizer guard. Reviewed patch SHA-256: 54afc118b882450e3e958120fc7b2e17f353ef3b3067be9816c986ee98571dde. The submitting contributor is responsible for the change and maintainer feedback.

Checklist:

  • Regression tests added.
  • Changelog fragment added.
  • AUTHORS entry added in alphabetical order.
  • Issue linked with Fixes #2844.
  • Maintainers may edit the branch and squash the commit.

Codex assistance is disclosed above and in the commit message; no agent email identity is claimed.

Fixes pytest-dev#2844. Guard finalizers from an older dependency generation and cover overrides with native pytester regression tests.

AI assistance: OpenAI Codex. Rongali Chaitanya reviewed and understood the implementation and tests.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong session scoped fixtures parametrization

1 participant