@@ -4012,43 +4012,53 @@ def test_fixture_named_request(testdir):
4012
4012
)
4013
4013
4014
4014
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)"""
4016
4017
testdir .makepyfile (
4017
4018
"""
4018
- from collections import Counter
4019
-
4020
4019
import pytest
4021
4020
4021
+ instantiated = []
4022
4022
4023
4023
@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))
4027
4026
4028
4027
4029
4028
@pytest.fixture(scope="session")
4030
4029
def fixture_2(request):
4031
- yield request.param
4030
+ instantiated.append(("fixture_2", request.param))
4032
4031
4033
4032
4034
4033
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"),
4041
4040
]
4042
4041
4043
-
4044
4042
@pytest.mark.parametrize(
4045
4043
"fixture_1,fixture_2", scenarios, indirect=["fixture_1", "fixture_2"]
4046
4044
)
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
4050
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
+ ]
4051
4061
"""
4052
4062
)
4053
4063
result = testdir .runpytest ()
4054
- result .assert_outcomes (passed = 6 )
4064
+ result .assert_outcomes (passed = 7 )
0 commit comments