fixtures: use early return in `_get_active_fixturedef`

This commit is contained in:
Ran Benita 2024-03-14 20:24:25 +02:00 committed by Bruno Oliveira
parent d208c1d4a5
commit 530be28575
1 changed files with 14 additions and 11 deletions

View File

@ -570,18 +570,21 @@ class FixtureRequest(abc.ABC):
self, argname: str self, argname: str
) -> Union["FixtureDef[object]", PseudoFixtureDef[object]]: ) -> Union["FixtureDef[object]", PseudoFixtureDef[object]]:
fixturedef = self._fixture_defs.get(argname) fixturedef = self._fixture_defs.get(argname)
if fixturedef is None: if fixturedef is not 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:
self._check_scope(fixturedef, fixturedef._scope) 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 return fixturedef
def _get_fixturestack(self) -> List["FixtureDef[Any]"]: def _get_fixturestack(self) -> List["FixtureDef[Any]"]: