fixtures: move "request" check early

This commit is contained in:
Ran Benita 2024-03-14 20:33:13 +02:00 committed by Bruno Oliveira
parent d217d68cde
commit 3c77aec1da
1 changed files with 7 additions and 7 deletions

View File

@ -569,18 +569,18 @@ class FixtureRequest(abc.ABC):
def _get_active_fixturedef( def _get_active_fixturedef(
self, argname: str self, argname: str
) -> Union["FixtureDef[object]", PseudoFixtureDef[object]]: ) -> Union["FixtureDef[object]", PseudoFixtureDef[object]]:
if argname == "request":
cached_result = (self, [0], None)
return PseudoFixtureDef(cached_result, Scope.Function)
# If we already finished computing a fixture by this name in this item,
# return it.
fixturedef = self._fixture_defs.get(argname) fixturedef = self._fixture_defs.get(argname)
if fixturedef is not None: if fixturedef is not None:
self._check_scope(fixturedef, fixturedef._scope) self._check_scope(fixturedef, fixturedef._scope)
return fixturedef return fixturedef
try:
fixturedef = self._getnextfixturedef(argname) fixturedef = self._getnextfixturedef(argname)
except FixtureLookupError:
if argname == "request":
cached_result = (self, [0], None)
return PseudoFixtureDef(cached_result, Scope.Function)
raise
# Prepare a SubRequest object for calling the fixture. # Prepare a SubRequest object for calling the fixture.
funcitem = self._pyfuncitem funcitem = self._pyfuncitem