GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pytest does not show inner exceptions in PEP-654 `ExceptionGroup`s · Issue #9159 · pytest-dev/pytest

Pytest does not show inner exceptions in PEP-654 ExceptionGroups #9159

New issue
Copy link
New issue
Copy link
Closed
Closed
Pytest does not show inner exceptions in PEP-654 ExceptionGroups#9159
Copy link
Labels
status: help wanteddevelopers would like help from experts on this topictopic: reportingrelated to terminal output and user-facing messages and errorstopic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed

Description

@Zac-HD
Zac-HD
opened on Oct 4, 2021
Issue body actions

Sometimes, you might have code which needs to raise multiple exceptions - for example if you retried an operation, had an error in async or cleanup code, or found multiple bugs with Hypothesis. This is pretty awkward though, and in current Pythons usually means losing some information, or at least making it less accessible.

PEP 654 adds "Exception Groups" as a standard "container" exception, to enable standardised handling of... groups of exceptions. (and except*, which Pytest can ignore)

I therefore propose that we should think about how to display a BaseExceptionGroup, with the potential tree of messages and tracebacks. This isn't urgent, since they'll be released in Python 3.11, but ideally we could support a backport sooner to enable downstream support in Hypothesis, pytest-trio, etc.

Reacted by Laurie O and Matthew Barber

Activity

  1. Zac-HD
    added
    type: enhancementnew feature or API change, should be merged into features branch
    topic: reportingrelated to terminal output and user-facing messages and errors
    topic: tracebacksrelated to displaying and handling of tracebacks
    on Oct 4, 2021
  2. bluetech commented on Oct 5, 2021

    @bluetech
    bluetech
    on Oct 5, 2021
    Member
    More actions

    For internal usage, see #8217.

  3. Zac-HD
    changed the title [-]Awesome traceback reporting for multiple errors with PEP-654 `ExceptionGroup` [/-] [+]Awesome traceback reporting for multiple errors with PEP-654 `ExceptionGroup` (in Python 3.11)[/+] on Oct 8, 2021
  4. agronholm commented on Jan 16, 2022

    @agronholm
    agronholm
    on Jan 16, 2022
    More actions

    Just mentioning here too that there is a backport available now.

    Reacted by Zac Hatfield-Dodds
    Reacted by Zac Hatfield-Dodds
  5. Zac-HD
    added
    type: bugproblem that needs to be addressed
    and removed
    type: enhancementnew feature or API change, should be merged into features branch
    on Apr 28, 2022
  6. Zac-HD
    changed the title [-]Awesome traceback reporting for multiple errors with PEP-654 `ExceptionGroup` (in Python 3.11)[/-] [+]Pytest does not show inner exceptions in PEP-654 `ExceptionGroup`s[/+] on Apr 28, 2022
  7. Zac-HD commented on Apr 28, 2022

    @Zac-HD
    Zac-HD
    on Apr 28, 2022
    MemberAuthor
    More actions

    We are now very close to the release of 3.11.0b1, and there's a backport in increasingly widespread use. I've therefore upgraded this to a bug, because inner exceptions are not displayed at all by default 😬

    from exceptiongroup import ExceptionGroup
    
    def f(): raise ValueError("From f()")
    def g(): raise RuntimeError("From g()")
    
    def main():
        excs = []
        for callback in [f, g]:
            try:
                callback()
            except Exception as err:
                excs.append(err)
        if excs:
            raise ExceptionGroup("Oops", excs)
    
    def test():
        main()

    The native tracebacks work well:

    # pytest --tb=native
    _________________________________________ test __________________________________________
      + Exception Group Traceback (most recent call last):
      |   File "test.py", line 24, in test
      |     main()
      |   File "test.py", line 20, in main
      |     raise ExceptionGroup("Oops", excs)
      | exceptiongroup.ExceptionGroup: Oops (2 sub-exceptions)
      +-+---------------- 1 ----------------
        | Traceback (most recent call last):
        |   File "test.py", line 16, in main
        |     call()
        |   File "test.py", line 5, in f
        |     raise ValueError("From f()")
        | ValueError: From f()
        +---------------- 2 ----------------
        | Traceback (most recent call last):
        |   File "test.py", line 16, in main
        |     call()
        |   File "test.py", line 9, in g
        |     raise RuntimeError("From g()")
        | RuntimeError: From g()
        +------------------------------------

    ...but Pytest's default traceback display drops everything under the top-level ExceptionGroup, from tracebacks to error messages and types.

    # pytest --tb=auto
    _____________________________________ test ______________________________________
    
        def test():
    >       main()
    
    test.py:24:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    
        def main():
            excs = []
            for call in [f, g]:
                try:
                    call()
                except Exception as err:
                    excs.append(err)
            if excs:
    >           raise ExceptionGroup("Oops", excs)
    E           exceptiongroup.ExceptionGroup: Oops (2 sub-exceptions)
    
    test.py:20: ExceptionGroup
  8. Zac-HD
    added
    status: help wanteddevelopers would like help from experts on this topic
    on Apr 28, 2022
  9. Zac-HD commented on May 1, 2022

    @Zac-HD
    Zac-HD
    on May 1, 2022
    MemberAuthor
    More actions

    @pytest-dev/core - I've bounced off this several times now, and could do with suggestions (or better yet a volunteer) to ensure that ExceptionGroup contents are in fact displayed when tests fail 🙏:pray:

    I also personally prefer --tb=native and so don't have much of a sense of how we should display ExceptionGroups, though I'd be satisfied with the native display to start with.

  10. Zac-HD
    added this to the 8.0 milestone on Jun 1, 2022
  11. Zac-HD
    modified the milestones: 8.0, 7.2 on Jun 15, 2022
  12. nicoddemus commented on Oct 9, 2022

    @nicoddemus
    nicoddemus
    on Oct 9, 2022
    Member
    More actions

    Should we split this issue in two, 1) supporting exception groups as if native (already merged), and 2) complete support, meaning showing exception groups in all tb-modes?

    I ask because this is scheduled for 7.2, and I believe we are in a satisfactory place for 7.2 with 1) in place.

  13. asottile commented on Oct 9, 2022

    @asottile
    asottile
    on Oct 9, 2022
    Member
    More actions

    yeah let's not block 7.2, we haven't released in quite a while and I think this is going to be pretty involved to land

  14. Zac-HD commented on Oct 9, 2022

    @Zac-HD
    Zac-HD
    on Oct 9, 2022
    MemberAuthor
    More actions

    Agreed, and I'd prefer to close this and open a new issue for 'more stylish display of ExceptionGroups' - we do at least display inner errors at all now!

  15. nicoddemus
    removed this from the 7.2 milestone on Oct 9, 2022
  16. nicoddemus commented on Oct 9, 2022

    @nicoddemus
    nicoddemus
    on Oct 9, 2022
    Member
    More actions

    Thanks folks.

    I just removed this issue from the 7.2 milestone then.

    We can open a new issue, or edit this one to clarify that pytest should honor the traceback mode (instead of falling back to native as it does now). Up to you @Zac-HD!

  17. Zac-HD commented on Oct 10, 2022

    @Zac-HD
    Zac-HD
    on Oct 10, 2022
    MemberAuthor
    More actions

    Closing this one; I'll leave opening the new one to someone with an opinion on what we should do next 😅

  18. Zac-HD
    closed this as completedon Oct 10, 2022
  19. jaypikay
    added a commit that references this issue on Apr 27, 2023

    chore(deps): update dependency pytest to v7 (#3)

    5c5ca77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: help wanteddevelopers would like help from experts on this topictopic: reportingrelated to terminal output and user-facing messages and errorstopic: tracebacksrelated to displaying and handling of tracebackstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.