Skip to content

Commit e46e77f

Browse files
The-Compilerolegpidsadnyi
authored andcommitted
Fix FixtureDef signature for newer pytest versions
In pytest-dev/pytest#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.
1 parent f8811bd commit e46e77f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pytest_bdd/steps.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,19 @@ def inject_fixture(request, arg, value):
284284
:param arg: argument name
285285
:param value: argument value
286286
"""
287-
fd = python.FixtureDef(
288-
fixturemanager=request._fixturemanager,
289-
baseid=None,
290-
argname=arg,
291-
func=lambda: value,
292-
scope="function",
293-
params=None,
294-
yieldctx=False,
295-
)
287+
fd_kwargs = {
288+
'fixturemanager': request._fixturemanager,
289+
'baseid': None,
290+
'argname': arg,
291+
'func': lambda: value,
292+
'scope': "function",
293+
'params': None,
294+
}
295+
296+
if 'yieldctx' in get_args(python.FixtureDef.__init__):
297+
fd_kwargs['yieldctx'] = False
298+
299+
fd = python.FixtureDef(**fd_kwargs)
296300
fd.cached_result = (value, 0, None)
297301

298302
old_fd = getattr(request, "_fixturedefs", {}).get(arg)

0 commit comments

Comments
 (0)