Skip to content

Commit c9a0881

Browse files
committed
Isolate the code that resolves the fixturefunc to a separate function
pytest_fixture_setup was somewhat convoluted because it was trying to do too many things.
1 parent 5167933 commit c9a0881

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/_pytest/fixtures.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -899,15 +899,10 @@ def __repr__(self):
899899
)
900900

901901

902-
def pytest_fixture_setup(fixturedef, request):
903-
""" Execution of fixture setup. """
904-
kwargs = {}
905-
for argname in fixturedef.argnames:
906-
fixdef = request._get_active_fixturedef(argname)
907-
result, arg_cache_key, exc = fixdef.cached_result
908-
request._check_scope(argname, request.scope, fixdef.scope)
909-
kwargs[argname] = result
910-
902+
def resolve_fixture_function(fixturedef, request):
903+
"""Gets the actual callable that can be called to obtain the fixture value, dealing with unittest-specific
904+
instances and bound methods.
905+
"""
911906
fixturefunc = fixturedef.func
912907
if fixturedef.unittest:
913908
if request.instance is not None:
@@ -921,6 +916,19 @@ def pytest_fixture_setup(fixturedef, request):
921916
fixturefunc = getimfunc(fixturedef.func)
922917
if fixturefunc != fixturedef.func:
923918
fixturefunc = fixturefunc.__get__(request.instance)
919+
return fixturefunc
920+
921+
922+
def pytest_fixture_setup(fixturedef, request):
923+
""" Execution of fixture setup. """
924+
kwargs = {}
925+
for argname in fixturedef.argnames:
926+
fixdef = request._get_active_fixturedef(argname)
927+
result, arg_cache_key, exc = fixdef.cached_result
928+
request._check_scope(argname, request.scope, fixdef.scope)
929+
kwargs[argname] = result
930+
931+
fixturefunc = resolve_fixture_function(fixturedef, request)
924932
my_cache_key = request.param_index
925933
try:
926934
result = call_fixture_func(fixturefunc, request, kwargs)

0 commit comments

Comments
 (0)