Skip to content

Commit

Permalink
fixtures: inline _compute_fixture_value
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech authored and nicoddemus committed Apr 27, 2024
1 parent 530be28 commit d217d68
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,26 +582,7 @@ def _get_active_fixturedef(
return PseudoFixtureDef(cached_result, Scope.Function)
raise

self._compute_fixture_value(fixturedef)

self._fixture_defs[argname] = fixturedef
return fixturedef

def _get_fixturestack(self) -> List["FixtureDef[Any]"]:
values = [request._fixturedef for request in self._iter_chain()]
values.reverse()
return values

def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
"""Create a SubRequest based on "self" and call the execute method
of the given FixtureDef object.
If the FixtureDef has cached the result it will do nothing, otherwise it will
setup and run the fixture, cache the value, and schedule a finalizer for it.
"""
# prepare a subrequest object before calling fixture function
# (latter managed by fixturedef)
argname = fixturedef.argname
# Prepare a SubRequest object for calling the fixture.
funcitem = self._pyfuncitem
try:
callspec = funcitem.callspec
Expand All @@ -627,7 +608,7 @@ def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
)
fail(msg, pytrace=False)
if has_params:
frame = inspect.stack()[3]
frame = inspect.stack()[2]
frameinfo = inspect.getframeinfo(frame[0])
source_path = absolutepath(frameinfo.filename)
source_lineno = frameinfo.lineno
Expand Down Expand Up @@ -658,6 +639,14 @@ def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None:
# Make sure the fixture value is cached, running it if it isn't
fixturedef.execute(request=subrequest)

self._fixture_defs[argname] = fixturedef
return fixturedef

def _get_fixturestack(self) -> List["FixtureDef[Any]"]:
values = [request._fixturedef for request in self._iter_chain()]
values.reverse()
return values


@final
class TopRequest(FixtureRequest):
Expand Down

0 comments on commit d217d68

Please sign in to comment.