1111from cleo .ui .exception_trace .component import ExceptionTrace
1212from tests .fixtures .exceptions import nested1
1313from tests .fixtures .exceptions import nested2
14+ from tests .fixtures .exceptions import raiser_with_suppressed_context
1415from tests .fixtures .exceptions import recursion
1516from tests .fixtures .exceptions import simple
1617
@@ -50,7 +51,7 @@ def test_render_debug_better_error_message() -> None:
5051
5152 trace .render (io )
5253
53- lineno = 47
54+ lineno = 48
5455 expected = f"""
5556 Stack trace:
5657
@@ -84,7 +85,7 @@ def test_render_debug_better_error_message_recursion_error() -> None:
8485 except RecursionError as e :
8586 trace = ExceptionTrace (e )
8687
87- lineno = 83
88+ lineno = 84
8889 trace .render (io )
8990
9091 expected = rf"""^
@@ -131,7 +132,7 @@ def test_render_very_verbose_better_error_message() -> None:
131132 expected = f"""
132133 Stack trace:
133134
134- 1 { trace ._get_relative_file_path (__file__ )} :125 in \
135+ 1 { trace ._get_relative_file_path (__file__ )} :126 in \
135136 test_render_very_verbose_better_error_message
136137 simple.simple_exception()
137138
@@ -183,7 +184,7 @@ def test_render_can_ignore_given_files() -> None:
183184 trace .ignore_files_in (rf"^{ re .escape (nested1 .__file__ )} $" )
184185 trace .render (io )
185186
186- lineno = 180
187+ lineno = 181
187188 expected = f"""
188189 Stack trace:
189190
@@ -221,7 +222,7 @@ def test_render_shows_ignored_files_if_in_debug_mode() -> None:
221222 trace .ignore_files_in (rf"^{ re .escape (nested1 .__file__ )} $" )
222223
223224 trace .render (io )
224- lineno = 218
225+ lineno = 219
225226 expected = f"""
226227 Stack trace:
227228
@@ -344,7 +345,7 @@ def test_simple_render_aborts_if_no_message() -> None:
344345 trace = ExceptionTrace (e .value )
345346
346347 trace .render (io , simple = True )
347- lineno = 342
348+ lineno = 343
348349
349350 expected = f"""
350351 AssertionError
@@ -364,3 +365,32 @@ def test_simple_render_aborts_if_no_message() -> None:
364365 { lineno + 4 } │ trace.render(io, simple=True)
365366"""
366367 assert expected == io .fetch_output ()
368+
369+
370+ def test_render_with_suppressed_context () -> None :
371+ io = BufferedIO ()
372+ lineno = 6
373+
374+ # Arrange: Trigger and catch the exception
375+ try :
376+ raiser_with_suppressed_context .raiser_with_suppressed_context ()
377+ except Exception as e :
378+ trace = ExceptionTrace (e )
379+
380+ trace .render (io )
381+
382+ expected = f"""\
383+
384+ RuntimeError
385+
386+ This error should be displayed.
387+
388+ at tests/fixtures/exceptions/raiser_with_suppressed_context.py:{ lineno } in raiser_with_suppressed_context
389+ { lineno - 4 } │ def raiser_with_suppressed_context() -> None:
390+ { lineno - 3 } │ try:
391+ { lineno - 2 } │ raise ValueError("This error should be suppressed.")
392+ { lineno - 1 } │ except ValueError:
393+ → { lineno + 0 } │ raise RuntimeError("This error should be displayed.") from None
394+ { lineno + 1 } │
395+ """
396+ assert expected == io .fetch_output ()
0 commit comments