mirror of https://github.com/pytest-dev/pytest.git
[8.0.x] Improve error message when using @pytest.fixture twice (#11958)
Co-authored-by: Florian Bruhin <me@the-compiler.org>
This commit is contained in:
parent
23b91d12de
commit
e6f6be3bc9
|
@ -1196,7 +1196,7 @@ class FixtureFunctionMarker:
|
|||
|
||||
if getattr(function, "_pytestfixturefunction", False):
|
||||
raise ValueError(
|
||||
"fixture is being applied more than once to the same function"
|
||||
f"@pytest.fixture is being applied more than once to the same function {function.__name__!r}"
|
||||
)
|
||||
|
||||
if hasattr(function, "pytestmark"):
|
||||
|
|
|
@ -4352,6 +4352,27 @@ def test_call_fixture_function_error():
|
|||
assert fix() == 1
|
||||
|
||||
|
||||
def test_fixture_double_decorator(pytester: Pytester) -> None:
|
||||
"""Check if an error is raised when using @pytest.fixture twice."""
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture
|
||||
def fixt():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = pytester.runpytest()
|
||||
result.assert_outcomes(errors=1)
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"E * ValueError: @pytest.fixture is being applied more than once to the same function 'fixt'"
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_fixture_param_shadowing(pytester: Pytester) -> None:
|
||||
"""Parametrized arguments would be shadowed if a fixture with the same name also exists (#5036)"""
|
||||
pytester.makepyfile(
|
||||
|
|
Loading…
Reference in New Issue