Skip to content

Commit 755083c

Browse files
authored
Merge pull request pytest-dev#12962 from jakkdl/fixturelookuperror_empty_stack
add assertion to FixtureLookupError.formatrepr
2 parents 76b8870 + cc1dcdf commit 755083c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/_pytest/fixtures.py

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

0 commit comments

Comments
 (0)