@@ -410,41 +410,6 @@ def node(self):
410410 """Underlying collection node (depends on current request scope)."""
411411 raise NotImplementedError ()
412412
413- def _getnextfixturedef (self , argname : str ) -> "FixtureDef[Any]" :
414- fixturedefs = self ._arg2fixturedefs .get (argname , None )
415- if fixturedefs is None :
416- # We arrive here because of a dynamic call to
417- # getfixturevalue(argname) usage which was naturally
418- # not known at parsing/collection time.
419- fixturedefs = self ._fixturemanager .getfixturedefs (argname , self ._pyfuncitem )
420- if fixturedefs is not None :
421- self ._arg2fixturedefs [argname ] = fixturedefs
422- # No fixtures defined with this name.
423- if fixturedefs is None :
424- raise FixtureLookupError (argname , self )
425- # The are no fixtures with this name applicable for the function.
426- if not fixturedefs :
427- raise FixtureLookupError (argname , self )
428-
429- # A fixture may override another fixture with the same name, e.g. a
430- # fixture in a module can override a fixture in a conftest, a fixture in
431- # a class can override a fixture in the module, and so on.
432- # An overriding fixture can request its own name (possibly indirectly);
433- # in this case it gets the value of the fixture it overrides, one level
434- # up.
435- # Check how many `argname`s deep we are, and take the next one.
436- # `fixturedefs` is sorted from furthest to closest, so use negative
437- # indexing to go in reverse.
438- index = - 1
439- for request in self ._iter_chain ():
440- if request .fixturename == argname :
441- index -= 1
442- # If already consumed all of the available levels, fail.
443- if - index > len (fixturedefs ):
444- raise FixtureLookupError (argname , self )
445-
446- return fixturedefs [index ]
447-
448413 @property
449414 def config (self ) -> Config :
450415 """The pytest config object associated with this request."""
@@ -580,7 +545,40 @@ def _get_active_fixturedef(
580545 self ._check_scope (fixturedef , fixturedef ._scope )
581546 return fixturedef
582547
583- fixturedef = self ._getnextfixturedef (argname )
548+ # Find the appropriate fixturedef.
549+ fixturedefs = self ._arg2fixturedefs .get (argname , None )
550+ if fixturedefs is None :
551+ # We arrive here because of a dynamic call to
552+ # getfixturevalue(argname) which was naturally
553+ # not known at parsing/collection time.
554+ fixturedefs = self ._fixturemanager .getfixturedefs (argname , self ._pyfuncitem )
555+ if fixturedefs is not None :
556+ self ._arg2fixturedefs [argname ] = fixturedefs
557+ # No fixtures defined with this name.
558+ if fixturedefs is None :
559+ raise FixtureLookupError (argname , self )
560+ # The are no fixtures with this name applicable for the function.
561+ if not fixturedefs :
562+ raise FixtureLookupError (argname , self )
563+
564+ # A fixture may override another fixture with the same name, e.g. a
565+ # fixture in a module can override a fixture in a conftest, a fixture in
566+ # a class can override a fixture in the module, and so on.
567+ # An overriding fixture can request its own name (possibly indirectly);
568+ # in this case it gets the value of the fixture it overrides, one level
569+ # up.
570+ # Check how many `argname`s deep we are, and take the next one.
571+ # `fixturedefs` is sorted from furthest to closest, so use negative
572+ # indexing to go in reverse.
573+ index = - 1
574+ for request in self ._iter_chain ():
575+ if request .fixturename == argname :
576+ index -= 1
577+ # If already consumed all of the available levels, fail.
578+ if - index > len (fixturedefs ):
579+ raise FixtureLookupError (argname , self )
580+
581+ fixturedef = fixturedefs [index ]
584582
585583 # Prepare a SubRequest object for calling the fixture.
586584 funcitem = self ._pyfuncitem
0 commit comments