From e46e77f8665b999e53dab01c9ce79b5409ac5c3b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 17 Jun 2016 10:56:57 +0200 Subject: [PATCH] Fix FixtureDef signature for newer pytest versions In https://github.com/pytest-dev/pytest/pull/1586 the "yieldctx" argument to FixtureDef was removed. This uses utils.get_args to check if it's needed or not so pytest-bdd works on pytest versions before and after that PR. --- pytest_bdd/steps.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pytest_bdd/steps.py b/pytest_bdd/steps.py index 653eae08..730f94ea 100644 --- a/pytest_bdd/steps.py +++ b/pytest_bdd/steps.py @@ -284,15 +284,19 @@ def inject_fixture(request, arg, value): :param arg: argument name :param value: argument value """ - fd = python.FixtureDef( - fixturemanager=request._fixturemanager, - baseid=None, - argname=arg, - func=lambda: value, - scope="function", - params=None, - yieldctx=False, - ) + fd_kwargs = { + 'fixturemanager': request._fixturemanager, + 'baseid': None, + 'argname': arg, + 'func': lambda: value, + 'scope': "function", + 'params': None, + } + + if 'yieldctx' in get_args(python.FixtureDef.__init__): + fd_kwargs['yieldctx'] = False + + fd = python.FixtureDef(**fd_kwargs) fd.cached_result = (value, 0, None) old_fd = getattr(request, "_fixturedefs", {}).get(arg)