From c9a088130947dfb8453bbd0ccec6bd1de219fa18 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 22 Jul 2018 09:37:41 -0300 Subject: [PATCH] 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. --- src/_pytest/fixtures.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index ca150580e..f384fa4c3 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -899,15 +899,10 @@ class FixtureDef(object): ) -def pytest_fixture_setup(fixturedef, request): - """ Execution of fixture setup. """ - kwargs = {} - for argname in fixturedef.argnames: - fixdef = request._get_active_fixturedef(argname) - result, arg_cache_key, exc = fixdef.cached_result - request._check_scope(argname, request.scope, fixdef.scope) - kwargs[argname] = result - +def resolve_fixture_function(fixturedef, request): + """Gets the actual callable that can be called to obtain the fixture value, dealing with unittest-specific + instances and bound methods. + """ fixturefunc = fixturedef.func if fixturedef.unittest: if request.instance is not None: @@ -921,6 +916,19 @@ def pytest_fixture_setup(fixturedef, request): fixturefunc = getimfunc(fixturedef.func) if fixturefunc != fixturedef.func: fixturefunc = fixturefunc.__get__(request.instance) + return fixturefunc + + +def pytest_fixture_setup(fixturedef, request): + """ Execution of fixture setup. """ + kwargs = {} + for argname in fixturedef.argnames: + fixdef = request._get_active_fixturedef(argname) + result, arg_cache_key, exc = fixdef.cached_result + request._check_scope(argname, request.scope, fixdef.scope) + kwargs[argname] = result + + fixturefunc = resolve_fixture_function(fixturedef, request) my_cache_key = request.param_index try: result = call_fixture_func(fixturefunc, request, kwargs)