@@ -449,7 +449,8 @@ def test_lookup_error(unknown):
449449 "*ERROR at setup of test_lookup_error*" ,
450450 " def test_lookup_error(unknown):*" ,
451451 "E fixture 'unknown' not found" ,
452- "> available fixtures:*a_fixture,*b_fixture,*c_fixture,*d_fixture*monkeypatch,*" , # sorted
452+ "> available fixtures:*a_fixture,*b_fixture,*c_fixture,*d_fixture*monkeypatch,*" ,
453+ # sorted
453454 "> use 'py*test --fixtures *' for help on them." ,
454455 "*1 error*" ,
455456 ]
@@ -4009,3 +4010,55 @@ def test_fixture_named_request(testdir):
40094010 " *test_fixture_named_request.py:5" ,
40104011 ]
40114012 )
4013+
4014+
4015+ def test_indirect_fixture_does_not_break_scope (testdir ):
4016+ """Ensure that fixture scope is respected when using indirect fixtures (#570)"""
4017+ testdir .makepyfile (
4018+ """
4019+ import pytest
4020+
4021+ instantiated = []
4022+
4023+ @pytest.fixture(scope="session")
4024+ def fixture_1(request):
4025+ instantiated.append(("fixture_1", request.param))
4026+
4027+
4028+ @pytest.fixture(scope="session")
4029+ def fixture_2(request):
4030+ instantiated.append(("fixture_2", request.param))
4031+
4032+
4033+ scenarios = [
4034+ ("A", "a1"),
4035+ ("A", "a2"),
4036+ ("B", "b1"),
4037+ ("B", "b2"),
4038+ ("C", "c1"),
4039+ ("C", "c2"),
4040+ ]
4041+
4042+ @pytest.mark.parametrize(
4043+ "fixture_1,fixture_2", scenarios, indirect=["fixture_1", "fixture_2"]
4044+ )
4045+ def test_create_fixtures(fixture_1, fixture_2):
4046+ pass
4047+
4048+
4049+ def test_check_fixture_instantiations():
4050+ assert instantiated == [
4051+ ('fixture_1', 'A'),
4052+ ('fixture_2', 'a1'),
4053+ ('fixture_2', 'a2'),
4054+ ('fixture_1', 'B'),
4055+ ('fixture_2', 'b1'),
4056+ ('fixture_2', 'b2'),
4057+ ('fixture_1', 'C'),
4058+ ('fixture_2', 'c1'),
4059+ ('fixture_2', 'c2'),
4060+ ]
4061+ """
4062+ )
4063+ result = testdir .runpytest ()
4064+ result .assert_outcomes (passed = 7 )
0 commit comments