Merge pull request #11228 from bluetech/fixtures-check-scope-test

fixtures: add a test for a currently non-covered scope mismatch scenario
This commit is contained in:
Ronny Pfannschmidt 2023-07-18 08:59:55 +02:00 committed by GitHub
commit 7c30f674c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -2464,6 +2464,31 @@ class TestFixtureMarker:
["*ScopeMismatch*You tried*function*session*request*"]
)
def test_scope_mismatch_already_computed_dynamic(self, pytester: Pytester) -> None:
pytester.makepyfile(
test_it="""
import pytest
@pytest.fixture(scope="function")
def fixfunc(): pass
@pytest.fixture(scope="module")
def fixmod(fixfunc): pass
def test_it(request, fixfunc):
request.getfixturevalue("fixmod")
""",
)
result = pytester.runpytest()
assert result.ret == ExitCode.TESTS_FAILED
result.stdout.fnmatch_lines(
[
"*ScopeMismatch*involved factories*",
"test_it.py:6: def fixmod(fixfunc)",
]
)
def test_dynamic_scope(self, pytester: Pytester) -> None:
pytester.makeconftest(
"""