Skip to content

Commit 8465ae7

Browse files
jakkdlGlyphack
authored andcommitted
add assertion to FixtureLookupError.formatrepr
1 parent 5c268e2 commit 8465ae7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/_pytest/fixtures.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,15 @@ def formatrepr(self) -> FixtureLookupErrorRepr:
803803
stack = [self.request._pyfuncitem.obj]
804804
stack.extend(map(lambda x: x.func, self.fixturestack))
805805
msg = self.msg
806+
# This function currently makes an assumption that a non-None msg means we
807+
# have a non-empty `self.fixturestack`. This is currently true, but if
808+
# somebody at some point want to extend the use of FixtureLookupError to
809+
# new cases it might break.
810+
# Add the assert to make it clearer to developer that this will fail, otherwise
811+
# it crashes because `fspath` does not get set due to `stack` being empty.
812+
assert (
813+
self.msg is None or self.fixturestack
814+
), "formatrepr assumptions broken, rewrite it to handle it"
806815
if msg is not None:
807816
# The last fixture raise an error, let's present
808817
# it at the requesting side.

0 commit comments

Comments
 (0)