MCPcopy Create free account
hub / github.com/pytest-dev/pytest / execute

Method execute

src/_pytest/fixtures.py:1040–1069  ·  view source on GitHub ↗
(self, request: SubRequest)

Source from the content-addressed store, hash-verified

1038 self._finalizers = []
1039
1040 def execute(self, request: SubRequest) -> FixtureValue:
1041 # Get required arguments and register our own finish()
1042 # with their finalization.
1043 for argname in self.argnames:
1044 fixturedef = request._get_active_fixturedef(argname)
1045 if argname != "request":
1046 # PseudoFixtureDef is only for "request".
1047 assert isinstance(fixturedef, FixtureDef)
1048 fixturedef.addfinalizer(functools.partial(self.finish, request=request))
1049
1050 my_cache_key = self.cache_key(request)
1051 if self.cached_result is not None:
1052 # note: comparison with `==` can fail (or be expensive) for e.g.
1053 # numpy arrays (#6497).
1054 cache_key = self.cached_result[1]
1055 if my_cache_key is cache_key:
1056 if self.cached_result[2] is not None:
1057 _, val, tb = self.cached_result[2]
1058 raise val.with_traceback(tb)
1059 else:
1060 result = self.cached_result[0]
1061 return result
1062 # We have a previous but differently parametrized fixture instance
1063 # so we need to tear it down before creating a new one.
1064 self.finish(request)
1065 assert self.cached_result is None
1066
1067 hook = self._fixturemanager.session.gethookproxy(request.node.path)
1068 result = hook.pytest_fixture_setup(fixturedef=self, request=request)
1069 return result
1070
1071 def cache_key(self, request: SubRequest) -> object:
1072 return request.param_index if not hasattr(request, "param") else request.param

Callers 1

Calls 5

cache_keyMethod · 0.95
finishMethod · 0.95
addfinalizerMethod · 0.45
gethookproxyMethod · 0.45

Tested by

no test coverage detected