Merge pull request #2849 from ApaDoctor/disable-repeated-fixture

provide error fixture applied to the same func
This commit is contained in:
Ronny Pfannschmidt 2018-04-24 06:36:54 +02:00 committed by GitHub
commit 6e62fc98ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -851,6 +851,11 @@ class FixtureFunctionMarker(object):
if isclass(function):
raise ValueError(
"class fixtures not supported (may be in the future)")
if getattr(function, "_pytestfixturefunction", False):
raise ValueError(
"fixture is being applied more than once to the same function")
function._pytestfixturefunction = self
return function

1
changelog/2334.feature Normal file
View File

@ -0,0 +1 @@
Now when ``@pytest.fixture`` is applied more than once to the same function a ``ValueError`` is raised. This buggy behavior would cause surprising problems and if was working for a test suite it was mostly by accident.

View File

@ -2992,6 +2992,14 @@ class TestShowFixtures(object):
Hi from test module
''')
def test_fixture_disallow_twice(self):
"""Test that applying @pytest.fixture twice generates an error (#2334)."""
with pytest.raises(ValueError):
@pytest.fixture
@pytest.fixture
def foo():
pass
@pytest.mark.parametrize('flavor', ['fixture', 'yield_fixture'])
class TestContextManagerFixtureFuncs(object):