Skip to content

Commit 686f9e0

Browse files
committed
fixtures: remove unneeded optimization from _getnextfixturedef
According to my understanding, this code, which handles obtaining the relevant fixturedefs when a dynamic `getfixturevalue` is used, has an optimization where it only grabs fixturedefs that are visible to the *parent* of the item, instead of the item itself, under the assumption that a fixturedef can't be visible to a single item, only to a collector. Remove this optimization for the following reasons: - It doesn't save much (one loop iteration in `matchfactories`) - It slightly complicates the complex fixtures code - If some plugin wants to make a fixture visible only to a single item, why not let it? - In the static case (`getfixtureclosure`), this optimization is not done (despite the confusing name `parentnode`, it is *not* the parent node). This is inconsistent.
1 parent 98b008f commit 686f9e0

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/_pytest/fixtures.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,7 @@ def _getnextfixturedef(self, argname: str) -> "FixtureDef[Any]":
413413
# We arrive here because of a dynamic call to
414414
# getfixturevalue(argname) usage which was naturally
415415
# not known at parsing/collection time.
416-
parent = self._pyfuncitem.parent
417-
assert parent is not None
418-
fixturedefs = self._fixturemanager.getfixturedefs(argname, parent)
416+
fixturedefs = self._fixturemanager.getfixturedefs(argname, self._pyfuncitem)
419417
if fixturedefs is not None:
420418
self._arg2fixturedefs[argname] = fixturedefs
421419
# No fixtures defined with this name.

0 commit comments

Comments
 (0)