Skip to content

Feature Suggestion: Collect multiple exceptions from hook implementations #419

Closed
@MrGreenTea

Description

@MrGreenTea

Currently, if one hook implementation raises an exception the rest of the implementations of that hook won't be called. This is fine in most cases, but we have some hooks for teardowns of operations and these should always be called and pytest could also have a use for this (see pytest#8217)

Our current workaround is a patch on the internal pluggy implementation to make sure all hook implementations are called and gathering all exceptions, then raising them together. This hack could form a basis for a more correct implementation and I'd be willing to work on a PR for this feature, should you accept the suggestion.

I believe it could work as a mode in the hookspec, so look something like this:

@hookspec(force_all_impls=True)  # I don't have a good name for this yet
def example_teardown():
    ...

With the addition of exception groups to python I believe this can work quite nicely.

I'm open to all feedback and think this feature needs a more in-depth discussion then I provided as of yet, but wanted to get this discussion started.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions