Skip to content

Scoped fixtures are not rebuilt when the fixtures they depend on change #14095

@rgilton

Description

@rgilton

When module-scoped fixture b depends on module-scoped fixture a, I was expecting fixture b to be rebuilt if the value/source of a was changed. In code, I expect all of the following assertions to succeed:

from pytest import fixture

@fixture(scope="module")
def a():
    return 0

@fixture(scope="module")
def b(a):
    return a

def test_b_is_zero(b):
    assert b == 0

class TestClass:
    @fixture(scope="module")
    def a(self):
        return 1

    def test_b_is_one(self, b):
        assert b == 1

However, the fixture that the test within the class is presented with is not as expected:

============================================ test session starts =============================================
platform linux -- Python 3.14.0, pytest-9.0.2, pluggy-1.6.0 -- /home/rob/tmp/fixtures/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/rob/tmp/fixtures
configfile: pyproject.toml
collected 2 items                                                                                            

test_a.py::test_b_is_zero PASSED                                                                       [ 50%]
test_a.py::TestClass::test_b_is_one FAILED                                                             [100%]

================================================== FAILURES ==================================================
__________________________________________ TestClass.test_b_is_one ___________________________________________

self = <test_a.TestClass object at 0x7f235325fb10>, b = 0

    def test_b_is_one(self, b):
>       assert b == 1
E       assert 0 == 1

test_a.py:24: AssertionError
========================================== short test summary info ===========================================
FAILED test_a.py::TestClass::test_b_is_one - assert 0 == 1
======================================== 1 failed, 1 passed in 0.03s =========================================
% uv pip list
Package   Version
--------- -------
iniconfig 2.3.0
packaging 25.0
pluggy    1.6.0
pygments  2.19.2
pytest    9.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions