Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve CHANGELOG and make test easier to understand for #570
  • Loading branch information
nicoddemus committed Aug 30, 2019
commit 35b3b1097ffc576b11cd8ad205103666a90e2344
3 changes: 2 additions & 1 deletion changelog/570.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Fix the scope behavior with indirect fixtures.
Fixed long standing issue where fixture scope was not respected when indirect fixtures were used during
parametrization.
46 changes: 28 additions & 18 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4012,43 +4012,53 @@ def test_fixture_named_request(testdir):
)


def test_indirect_fixture(testdir):
def test_indirect_fixture_does_not_break_scope(testdir):
"""Ensure that fixture scope is respected when using indirect fixtures (#570)"""
testdir.makepyfile(
"""
from collections import Counter

import pytest

instantiated = []

@pytest.fixture(scope="session")
def fixture_1(request, count=Counter()):
count[request.param] += 1
yield count[request.param]
def fixture_1(request):
instantiated.append(("fixture_1", request.param))


@pytest.fixture(scope="session")
def fixture_2(request):
yield request.param
instantiated.append(("fixture_2", request.param))


scenarios = [
("a", "a1"),
("a", "a2"),
("b", "b1"),
("b", "b2"),
("c", "c1"),
("c", "c2"),
("A", "a1"),
("A", "a2"),
("B", "b1"),
("B", "b2"),
("C", "c1"),
("C", "c2"),
]


@pytest.mark.parametrize(
"fixture_1,fixture_2", scenarios, indirect=["fixture_1", "fixture_2"]
)
def test_it(fixture_1, fixture_2):
assert fixture_1 == 1
assert fixture_2[1] in ("1", "2")
def test_create_fixtures(fixture_1, fixture_2):
pass


def test_check_fixture_instantiations():
assert instantiated == [
('fixture_1', 'A'),
('fixture_2', 'a1'),
('fixture_2', 'a2'),
('fixture_1', 'B'),
('fixture_2', 'b1'),
('fixture_2', 'b2'),
('fixture_1', 'C'),
('fixture_2', 'c1'),
('fixture_2', 'c2'),
]
"""
)
result = testdir.runpytest()
result.assert_outcomes(passed=6)
result.assert_outcomes(passed=7)