Allow custom fixture names for fixtures

When defining a fixture in the same module as where it is used, the
function argument shadows the fixture name, which a) annoys pylint and
b) can lead to bugs where you forget to request a fixture into a test
method.

This allows one to define fixtures with a different name than the name
of the function, bypassing that problem.
This commit is contained in:
Mike Lundy
2016-03-08 18:16:57 -08:00
parent c2b9196a7c
commit 9577120592
4 changed files with 33 additions and 5 deletions

View File

@@ -2691,3 +2691,14 @@ class TestContextManagerFixtureFuncs:
*def arg1*
""")
def test_custom_name(self, testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(name='meow')
def arg1():
return 'mew'
def test_1(meow):
print(meow)
""")
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines("*mew*")