Skip to content

Commit 7320e9e

Browse files
committed
fixtures: make FixtureLookupError work from TopRequest with custom message
In this case let's just show the test function.
1 parent 4808728 commit 7320e9e

1 file changed

Lines changed: 1 addition & 10 deletions

File tree

src/_pytest/fixtures.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -808,16 +808,7 @@ def formatrepr(self) -> FixtureLookupErrorRepr:
808808
stack = [self.request._pyfuncitem.obj]
809809
stack.extend(map(lambda x: x.func, self.fixturestack))
810810
msg = self.msg
811-
# This function currently makes an assumption that a non-None msg means we
812-
# have a non-empty `self.fixturestack`. This is currently true, but if
813-
# somebody at some point want to extend the use of FixtureLookupError to
814-
# new cases it might break.
815-
# Add the assert to make it clearer to developer that this will fail, otherwise
816-
# it crashes because `fspath` does not get set due to `stack` being empty.
817-
assert self.msg is None or self.fixturestack, (
818-
"formatrepr assumptions broken, rewrite it to handle it"
819-
)
820-
if msg is not None:
811+
if msg is not None and len(stack) > 1:
821812
# The last fixture raise an error, let's present
822813
# it at the requesting side.
823814
stack = stack[:-1]

0 commit comments

Comments
 (0)