Skip to content

Commit

Permalink
fixtures: use early return in _get_active_fixturedef
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech authored and nicoddemus committed Apr 27, 2024
1 parent d208c1d commit 530be28
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,18 +570,21 @@ def _get_active_fixturedef(
self, argname: str
) -> Union["FixtureDef[object]", PseudoFixtureDef[object]]:
fixturedef = self._fixture_defs.get(argname)
if fixturedef is None:
try:
fixturedef = self._getnextfixturedef(argname)
except FixtureLookupError:
if argname == "request":
cached_result = (self, [0], None)
return PseudoFixtureDef(cached_result, Scope.Function)
raise
self._compute_fixture_value(fixturedef)
self._fixture_defs[argname] = fixturedef
else:
if fixturedef is not None:
self._check_scope(fixturedef, fixturedef._scope)
return fixturedef

try:
fixturedef = self._getnextfixturedef(argname)
except FixtureLookupError:
if argname == "request":
cached_result = (self, [0], None)
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]"]:
Expand Down

0 comments on commit 530be28

Please sign in to comment.