fixtures: improve fixture scope mismatch message

- Separate the requesting from the requested.

- Avoid the term "factory", I think most people don't distinguish
  between "fixture" and "fixture function" (i.e. "factory") and would
  find the term "factory" unfamiliar.
This commit is contained in:
Ran Benita
2024-03-08 23:08:28 +02:00
parent a9d1f55a0f
commit 71671f60b5
2 changed files with 15 additions and 5 deletions

View File

@@ -1247,8 +1247,9 @@ class TestFixtureUsages:
result = pytester.runpytest()
result.stdout.fnmatch_lines(
[
"*ScopeMismatch*involved factories*",
"*ScopeMismatch*Requesting fixture stack*",
"test_receives_funcargs_scope_mismatch.py:6: def arg2(arg1)",
"Requested fixture:",
"test_receives_funcargs_scope_mismatch.py:2: def arg1()",
"*1 error*",
]
@@ -1274,7 +1275,13 @@ class TestFixtureUsages:
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(
["*ScopeMismatch*involved factories*", "* def arg2*", "*1 error*"]
[
"*ScopeMismatch*Requesting fixture stack*",
"* def arg2(arg1)",
"Requested fixture:",
"* def arg1()",
"*1 error*",
],
)
def test_invalid_scope(self, pytester: Pytester) -> None:
@@ -2488,8 +2495,10 @@ class TestFixtureMarker:
assert result.ret == ExitCode.TESTS_FAILED
result.stdout.fnmatch_lines(
[
"*ScopeMismatch*involved factories*",
"*ScopeMismatch*Requesting fixture stack*",
"test_it.py:6: def fixmod(fixfunc)",
"Requested fixture:",
"test_it.py:3: def fixfunc()",
]
)