Fix custom name for yield_fixtures
This commit is contained in:
parent
366879db27
commit
d712428d33
|
@ -175,7 +175,7 @@ def fixture(scope="function", params=None, autouse=False, ids=None, name=None):
|
||||||
params = list(params)
|
params = list(params)
|
||||||
return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)
|
return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)
|
||||||
|
|
||||||
def yield_fixture(scope="function", params=None, autouse=False, ids=None):
|
def yield_fixture(scope="function", params=None, autouse=False, ids=None, name=None):
|
||||||
""" (return a) decorator to mark a yield-fixture factory function
|
""" (return a) decorator to mark a yield-fixture factory function
|
||||||
(EXPERIMENTAL).
|
(EXPERIMENTAL).
|
||||||
|
|
||||||
|
@ -184,12 +184,12 @@ def yield_fixture(scope="function", params=None, autouse=False, ids=None):
|
||||||
statement to provide a fixture. See
|
statement to provide a fixture. See
|
||||||
http://pytest.org/en/latest/yieldfixture.html for more info.
|
http://pytest.org/en/latest/yieldfixture.html for more info.
|
||||||
"""
|
"""
|
||||||
if callable(scope) and params is None and autouse == False:
|
if callable(scope) and params is None and not autouse:
|
||||||
# direct decoration
|
# direct decoration
|
||||||
return FixtureFunctionMarker(
|
return FixtureFunctionMarker(
|
||||||
"function", params, autouse, yieldctx=True)(scope)
|
"function", params, autouse, name=name, yieldctx=True, ids=ids)(scope)
|
||||||
else:
|
else:
|
||||||
return FixtureFunctionMarker(scope, params, autouse,
|
return FixtureFunctionMarker(scope, params, autouse, name=name,
|
||||||
yieldctx=True, ids=ids)
|
yieldctx=True, ids=ids)
|
||||||
|
|
||||||
defaultfuncargprefixmarker = fixture()
|
defaultfuncargprefixmarker = fixture()
|
||||||
|
|
|
@ -2693,15 +2693,14 @@ class TestContextManagerFixtureFuncs:
|
||||||
*test_yields*:2*
|
*test_yields*:2*
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# TODO: yield_fixture should work as well (this is bugged right now)
|
def test_custom_name(self, testdir, flavor):
|
||||||
def test_custom_name(testdir):
|
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import pytest
|
import pytest
|
||||||
@pytest.fixture(name='meow')
|
@pytest.{flavor}(name='meow')
|
||||||
def arg1():
|
def arg1():
|
||||||
return 'mew'
|
return 'mew'
|
||||||
def test_1(meow):
|
def test_1(meow):
|
||||||
print(meow)
|
print(meow)
|
||||||
""")
|
""".format(flavor=flavor))
|
||||||
result = testdir.runpytest("-s")
|
result = testdir.runpytest("-s")
|
||||||
result.stdout.fnmatch_lines("*mew*")
|
result.stdout.fnmatch_lines("*mew*")
|
||||||
|
|
Loading…
Reference in New Issue