From d712428d3343a77fb90b66eefeb8d769d293ca9c Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 7 Jun 2016 20:05:07 -0300 Subject: [PATCH] Fix custom name for yield_fixtures --- _pytest/python.py | 8 ++++---- testing/python/fixture.py | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 7bbf20cc9..4dea59c2c 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -175,7 +175,7 @@ def fixture(scope="function", params=None, autouse=False, ids=None, name=None): params = list(params) 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 (EXPERIMENTAL). @@ -184,12 +184,12 @@ def yield_fixture(scope="function", params=None, autouse=False, ids=None): statement to provide a fixture. See 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 return FixtureFunctionMarker( - "function", params, autouse, yieldctx=True)(scope) + "function", params, autouse, name=name, yieldctx=True, ids=ids)(scope) else: - return FixtureFunctionMarker(scope, params, autouse, + return FixtureFunctionMarker(scope, params, autouse, name=name, yieldctx=True, ids=ids) defaultfuncargprefixmarker = fixture() diff --git a/testing/python/fixture.py b/testing/python/fixture.py index 5cfb4751d..8b8497db0 100644 --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -2693,15 +2693,14 @@ class TestContextManagerFixtureFuncs: *test_yields*:2* """) -# TODO: yield_fixture should work as well (this is bugged right now) -def test_custom_name(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*") + def test_custom_name(self, testdir, flavor): + testdir.makepyfile(""" + import pytest + @pytest.{flavor}(name='meow') + def arg1(): + return 'mew' + def test_1(meow): + print(meow) + """.format(flavor=flavor)) + result = testdir.runpytest("-s") + result.stdout.fnmatch_lines("*mew*")