Skip to content

add assertion to FixtureLookupError.formatrepr #12962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
Loading