Skip to content

ExceptionGroups do not respect __tracebackhide__ #14036

@jakkdl

Description

@jakkdl

repro:

def g1():
    __tracebackhide__ = True
    str.does_not_exist

def f3():
    __tracebackhide__ = True
    1 / 0

def f2():
    __tracebackhide__ = True
    exc = None
    try:
        f3()
    except Exception as e:
        exc = e
    exc2 = None
    try:
        g1()
    except Exception as e:
        exc2 = e
    raise ExceptionGroup("blah", [exc, exc2])


def f1():
    __tracebackhide__ = True
    f2()

def test():
    f1()

actual output:

____________________________________ test _____________________________________
  + Exception Group Traceback (most recent call last):
  |   File "/home/h/Git/pytest/hide_tb/foo.py", line 33, in test
  |     f1()
  |     ~~^^
  |   File "/home/h/Git/pytest/hide_tb/foo.py", line 30, in f1
  |     f2()
  |     ~~^^
  |   File "/home/h/Git/pytest/hide_tb/foo.py", line 25, in f2
  |     raise ExceptionGroup("blah", [exc, exc2])
  | ExceptionGroup: blah (2 sub-exceptions)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/h/Git/pytest/hide_tb/foo.py", line 17, in f2
    |     f3()
    |     ~~^^
    |   File "/home/h/Git/pytest/hide_tb/foo.py", line 11, in f3
    |     f4()
    |     ~~^^
    |   File "/home/h/Git/pytest/hide_tb/foo.py", line 7, in f4
    |     1 / 0
    |     ~~^~~
    | ZeroDivisionError: division by zero
    +---------------- 2 ----------------
    | Traceback (most recent call last):
    |   File "/home/h/Git/pytest/hide_tb/foo.py", line 22, in f2
    |     g1()
    |     ~~^^
    |   File "/home/h/Git/pytest/hide_tb/foo.py", line 3, in g1
    |     str.does_not_exist
    | AttributeError: type object 'str' has no attribute 'does_not_exist'
    +------------------------------------

expected output

____________________________________ test _____________________________________
  + Exception Group Traceback (most recent call last):
  |   File "/home/h/Git/pytest/hide_tb/foo.py", line 33, in test
  |     f1()
  |     ~~^^
  | ExceptionGroup: blah (2 sub-exceptions)
  +-+---------------- 1 ----------------
    | ZeroDivisionError: division by zero
    +---------------- 2 ----------------
    | AttributeError: type object 'str' has no attribute 'does_not_exist'
    +------------------------------------

This is as much a feature request as it is a bug - the logic has simply not been implemented given that exception groups always fall back to displaying using tbstyle "native". See #9159

Designing the output of exception groups to be as pretty as the other "tbstyle"s would require a lot of design decisions, but a minimal implementation could keep the look of "native" except add features such as traceback filtering.

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