Skip to content

When multiple fixture finalizers raise, only first exception is reported #12047

@bluetech

Description

@bluetech

As mentioned in the XXX comment here:

pytest/src/_pytest/fixtures.py

Lines 1019 to 1032 in 6ed0051

def finish(self, request: SubRequest) -> None:
exc = None
try:
while self._finalizers:
try:
func = self._finalizers.pop()
func()
except BaseException as e:
# XXX Only first exception will be seen by user,
# ideally all should be reported.
if exc is None:
exc = e
if exc:
raise exc

This means information on the extra errors that occurred is not reported, which should never happen ideally.

We should instead raise an exception group in this case, like we do for nodes since pytest 7.3 (#10226).

Metadata

Metadata

Assignees

Labels

topic: fixturesanything involving fixtures directly or indirectlytopic: reportingrelated to terminal output and user-facing messages and errors

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions