Skip to content

Commit 7c30f67

Browse files
Merge pull request #11228 from bluetech/fixtures-check-scope-test
fixtures: add a test for a currently non-covered scope mismatch scenario
2 parents 02ba39b + 396bfbf commit 7c30f67

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)