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:
@@ -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*")
|
||||
|
||||
Reference in New Issue
Block a user