MCPcopy
hub / github.com/Textualize/rich / test_nested_exception

Function test_nested_exception

tests/test_traceback.py:138–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136
137
138def test_nested_exception():
139 console = Console(width=100, file=io.StringIO())
140 value_error_message = "ValueError because of ZeroDivisionError"
141
142 try:
143 try:
144 1 / 0
145 except ZeroDivisionError:
146 raise ValueError(value_error_message)
147 except Exception:
148 console.print_exception()
149 exception_text = console.file.getvalue()
150
151 text_should_contain = [
152 value_error_message,
153 "ZeroDivisionError",
154 "ValueError",
155 "During handling of the above exception",
156 ]
157
158 for msg in text_should_contain:
159 assert msg in exception_text
160
161 # ZeroDivisionError should come before ValueError
162 assert exception_text.find("ZeroDivisionError") < exception_text.find("ValueError")
163
164
165def test_caused_exception():

Callers

nothing calls this directly

Calls 2

print_exceptionMethod · 0.95
ConsoleClass · 0.90

Tested by

no test coverage detected