pytest-dev / pytest-dev/pytest

Fixtures are not rebuilt when param changes for a fixture they depend on, if the dependency is via getfixturevalue

Open
#14,103 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Minimal reproducer:

import pytest

@pytest.fixture(scope="session")
def foo(request):
    return request.param

@pytest.fixture(scope="session")
def bar(request):
    return request.getfixturevalue("foo")

@pytest.mark.parametrize("foo", [1], indirect=True)
def test_first(foo, bar):
    assert bar == 1

@pytest.mark.parametrize("foo", [2], indirect=True)
def test_second(foo, bar):
    assert bar == 2

test_second fails, because bar == 1.

The reason is that pytest currently only tracks static dependencies via argnames for the purposes of resetting dependent fixtures.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproducer and trace fixture invalidation for the getfixturevalue("foo") entry point, comparing it with static dependencies recorded through argnames. Add regression coverage for the two parametrized tests, then verify that the session-scoped bar fixture is rebuilt and test_second observes bar == 2.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.