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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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