cleo
cleo copied to clipboard
When rendering exceptions, `__suppress_context__` is not respected
Originally identified in https://github.com/python-poetry/poetry/pull/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