@@ -4012,43 +4012,53 @@ def test_fixture_named_request(testdir):
40124012 )
40134013
40144014
4015- def test_indirect_fixture (testdir ):
4015+ def test_indirect_fixture_does_not_break_scope (testdir ):
4016+ """Ensure that fixture scope is respected when using indirect fixtures (#570)"""
40164017 testdir .makepyfile (
40174018 """
4018- from collections import Counter
4019-
40204019 import pytest
40214020
4021+ instantiated = []
40224022
40234023 @pytest.fixture(scope="session")
4024- def fixture_1(request, count=Counter()):
4025- count[request.param] += 1
4026- yield count[request.param]
4024+ def fixture_1(request):
4025+ instantiated.append(("fixture_1", request.param))
40274026
40284027
40294028 @pytest.fixture(scope="session")
40304029 def fixture_2(request):
4031- yield request.param
4030+ instantiated.append(("fixture_2", request.param))
40324031
40334032
40344033 scenarios = [
4035- ("a ", "a1"),
4036- ("a ", "a2"),
4037- ("b ", "b1"),
4038- ("b ", "b2"),
4039- ("c ", "c1"),
4040- ("c ", "c2"),
4034+ ("A ", "a1"),
4035+ ("A ", "a2"),
4036+ ("B ", "b1"),
4037+ ("B ", "b2"),
4038+ ("C ", "c1"),
4039+ ("C ", "c2"),
40414040 ]
40424041
4043-
40444042 @pytest.mark.parametrize(
40454043 "fixture_1,fixture_2", scenarios, indirect=["fixture_1", "fixture_2"]
40464044 )
4047- def test_it(fixture_1, fixture_2):
4048- assert fixture_1 == 1
4049- assert fixture_2[1] in ("1", "2")
4045+ def test_create_fixtures(fixture_1, fixture_2):
4046+ pass
40504047
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+ ]
40514061 """
40524062 )
40534063 result = testdir .runpytest ()
4054- result .assert_outcomes (passed = 6 )
4064+ result .assert_outcomes (passed = 7 )
0 commit comments