Skip to content

Commit ecfab4d

Browse files
committed
fixtures: fix a typing ignore TODO
From understanding the code better I see this is the correct fix. The fixturedefs can be None if `request.getfixturevalue("doesnotexist")` is used. In practice there is no change in behavior because this mapping is used as `self._arg2fixturedefs.get(argname, None)` which ends up the same.
1 parent 2c80de5 commit ecfab4d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/_pytest/fixtures.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,13 @@ def _getnextfixturedef(self, argname: str) -> "FixtureDef[Any]":
464464
assert self._pyfuncitem.parent is not None
465465
parentid = self._pyfuncitem.parent.nodeid
466466
fixturedefs = self._fixturemanager.getfixturedefs(argname, parentid)
467-
# TODO: Fix this type ignore. Either add assert or adjust types.
468-
# Can this be None here?
469-
self._arg2fixturedefs[argname] = fixturedefs # type: ignore[assignment]
467+
if fixturedefs is not None:
468+
self._arg2fixturedefs[argname] = fixturedefs
469+
if fixturedefs is None:
470+
raise FixtureLookupError(argname, self)
470471
# fixturedefs list is immutable so we maintain a decreasing index.
471472
index = self._arg2index.get(argname, 0) - 1
472-
if fixturedefs is None or (-index > len(fixturedefs)):
473+
if -index > len(fixturedefs):
473474
raise FixtureLookupError(argname, self)
474475
self._arg2index[argname] = index
475476
return fixturedefs[index]

0 commit comments

Comments
 (0)