Skip to content

Commit 396bfbf

Browse files
committed
fixtures: add a test for a currently non-covered scope mismatch scenario
This test makes clear the need for the `_check_scope()` call in the `pytest_setup_fixture` impl in fixtures.py, which otherwise seems redundant with the one in `_compute_fixture_value`.
1 parent 02ba39b commit 396bfbf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

testing/python/fixtures.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,31 @@ def test_1(arg):
24642464
["*ScopeMismatch*You tried*function*session*request*"]
24652465
)
24662466

2467+
def test_scope_mismatch_already_computed_dynamic(self, pytester: Pytester) -> None:
2468+
pytester.makepyfile(
2469+
test_it="""
2470+
import pytest
2471+
2472+
@pytest.fixture(scope="function")
2473+
def fixfunc(): pass
2474+
2475+
@pytest.fixture(scope="module")
2476+
def fixmod(fixfunc): pass
2477+
2478+
def test_it(request, fixfunc):
2479+
request.getfixturevalue("fixmod")
2480+
""",
2481+
)
2482+
2483+
result = pytester.runpytest()
2484+
assert result.ret == ExitCode.TESTS_FAILED
2485+
result.stdout.fnmatch_lines(
2486+
[
2487+
"*ScopeMismatch*involved factories*",
2488+
"test_it.py:6: def fixmod(fixfunc)",
2489+
]
2490+
)
2491+
24672492
def test_dynamic_scope(self, pytester: Pytester) -> None:
24682493
pytester.makeconftest(
24692494
"""

0 commit comments

Comments
 (0)