Skip to content

When rendering exceptions, __suppress_context__ is not respected #454

@abn

Description

@abn

Originally identified in python-poetry/poetry#9870.

from cleo.io.buffered_io import BufferedIO
from cleo.ui.exception_trace import ExceptionTrace
from crashtest.inspector import Inspector

if __name__ == "__main__":
    io = BufferedIO()

    try:
        try:
            raise ValueError("ValueError")
        except ValueError:
            raise RuntimeError("RuntimeError") from None
    except Exception as e:
        # assert the condition
        assert e.__context__ is not None
        assert e.__suppress_context__

        # this is the high level impact
        ExceptionTrace(e).render(io)

        # this is the root cause
        assert not Inspector(e).has_previous_exception()
    finally:
        output = io.fetch_output()
        print(output)

        # if __suppress_context__ is respected this should not be displayed
        assert "The following error occurred when trying to handle this error:" not in output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions