Skip to content

Commit

Permalink
add assertion to FixtureLookupError.formatrepr
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl authored and mwychung committed Nov 15, 2024
1 parent f308043 commit 09e6ee2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,15 @@ def formatrepr(self) -> FixtureLookupErrorRepr:
stack = [self.request._pyfuncitem.obj]
stack.extend(map(lambda x: x.func, self.fixturestack))
msg = self.msg
# This function currently makes an assumption that a non-None msg means we
# have a non-empty `self.fixturestack`. This is currently true, but if
# somebody at some point want to extend the use of FixtureLookupError to
# new cases it might break.
# Add the assert to make it clearer to developer that this will fail, otherwise
# it crashes because `fspath` does not get set due to `stack` being empty.
assert (

Check warning on line 814 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L814

Added line #L814 was not covered by tests
self.msg is None or self.fixturestack
), "formatrepr assumptions broken, rewrite it to handle it"
if msg is not None:
# The last fixture raise an error, let's present
# it at the requesting side.
Expand Down

0 comments on commit 09e6ee2

Please sign in to comment.