GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Respect parametrization scope in fixture cache reuse by Ace-0-A · Pull Request #15112 · pytest-dev/pytest

Conversation

@Ace-0-A

@Ace-0-A Ace-0-A commented Sep 28, 2026

Copy link
Copy Markdown

Closes #11575.

I traced the bug to fixture cache reuse. Pytest compared only the parameter value, so a module-scoped result could be returned to a later function-scoped request when both parametrizations used the same value.

The fix records the effective parametrization scope with the cached result and checks it before reuse. The new test covers a module-scoped parametrization followed by a function-scoped one using the same value.

I ran the full test suite and pre-commit checks. All passed.

I used Codex as a development tool and reviewed the final change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Ace-0-A
Respect parametrization scope in fixture cache reuse
5619972
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 28, 2026
@RonnyPfannschmidt RonnyPfannschmidt mentioned this pull request Oct 9, 2026
Indirect parametrization with scope="function" does not always work #11575
Open
RonnyPfannschmidt
RonnyPfannschmidt requested changes Oct 9, 2026
View reviewed changes

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

Thanks, the cache change is correct and should stay: as long as a narrower param scope is allowed, tearing down and recreating is the only way not to hand out the wrong value. But it makes this case visibly more expensive. If tests are reordered (or simply interleaved), a module-scoped fixture is now set up several times within one module:

@pytest.fixture(scope="module")
def fx(request): ...

@pytest.mark.parametrize("fx", ["a"], scope="module", indirect=True)
def test1(fx): ...
@pytest.mark.parametrize("fx", ["a"], scope="function", indirect=True)
def test2(fx): ...
@pytest.mark.parametrize("fx", ["a"], scope="module", indirect=True)
def test3(fx): ...

In the order test1, test2, test3, the module-scoped a is set up three times.

We want to phase out narrower param scopes (see #11575 (comment)). Could you add to this PR:

  1. A PytestRemovedIn10Warning when an indirect parametrization's scope is narrower than the scope of the fixture it targets, naming the test, the fixture and both scopes, and saying it causes extra setup/teardown. Equal and wider scopes stay silent.
  2. An entry in doc/en/deprecations.rst, and a note in the scope docs of Metafunc.parametrize ("It will also override any fixture-function defined scope") that the param scope may only widen the fixture's scope.
  3. Tests: narrower scope warns, equal and wider scopes do not. Extend your existing test to assert the setup/teardown sequence for the interleaved order above.
  4. A deprecation changelog fragment for #11575 next to the existing bugfix one; the bugfix entry should mention that the fixture is now set up again for the narrower scope.

Generated by Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rongali-commits rongali-commits mentioned this pull request Oct 14, 2026
Rebuild cached fixtures when declared dependency definitions change #15177
Open
5 tasks done

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

Reviewers

@RonnyPfannschmidt RonnyPfannschmidt RonnyPfannschmidt requested changes

Requested changes must be addressed to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Indirect parametrization with scope="function" does not always work

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Ace-0-A @RonnyPfannschmidt
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.