Show More
@@ -298,6 +298,13 b' except Exception:' | |||||
298 | raise ValueError("Yikes") from None |
|
298 | raise ValueError("Yikes") from None | |
299 | """ |
|
299 | """ | |
300 |
|
300 | |||
|
301 | SYS_EXIT_WITH_CONTEXT_CODE = """ | |||
|
302 | try: | |||
|
303 | 1/0 | |||
|
304 | except Exception as e: | |||
|
305 | raise SystemExit(1) | |||
|
306 | """ | |||
|
307 | ||||
301 | def test_direct_cause_error(self): |
|
308 | def test_direct_cause_error(self): | |
302 | with tt.AssertPrints(["KeyError", "NameError", "direct cause"]): |
|
309 | with tt.AssertPrints(["KeyError", "NameError", "direct cause"]): | |
303 | ip.run_cell(self.DIRECT_CAUSE_ERROR_CODE) |
|
310 | ip.run_cell(self.DIRECT_CAUSE_ERROR_CODE) | |
@@ -306,6 +313,11 b' except Exception:' | |||||
306 | with tt.AssertPrints(["KeyError", "NameError", "During handling"]): |
|
313 | with tt.AssertPrints(["KeyError", "NameError", "During handling"]): | |
307 | ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE) |
|
314 | ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE) | |
308 |
|
315 | |||
|
316 | def test_sysexit_while_handling_error(self): | |||
|
317 | with tt.AssertPrints(["SystemExit", "to see the full traceback"]): | |||
|
318 | with tt.AssertNotPrints(["another exception"], suppress=False): | |||
|
319 | ip.run_cell(self.SYS_EXIT_WITH_CONTEXT_CODE) | |||
|
320 | ||||
309 | def test_suppress_exception_chaining(self): |
|
321 | def test_suppress_exception_chaining(self): | |
310 | with tt.AssertNotPrints("ZeroDivisionError"), \ |
|
322 | with tt.AssertNotPrints("ZeroDivisionError"), \ | |
311 | tt.AssertPrints("ValueError", suppress=False): |
|
323 | tt.AssertPrints("ValueError", suppress=False): |
@@ -552,28 +552,31 b' class ListTB(TBTools):' | |||||
552 | lines = ''.join(self._format_exception_only(etype, evalue)) |
|
552 | lines = ''.join(self._format_exception_only(etype, evalue)) | |
553 | out_list.append(lines) |
|
553 | out_list.append(lines) | |
554 |
|
554 | |||
555 | exception = self.get_parts_of_chained_exception(evalue) |
|
555 | # Find chained exceptions if we have a traceback (not for exception-only mode) | |
|
556 | if etb is not None: | |||
|
557 | exception = self.get_parts_of_chained_exception(evalue) | |||
556 |
|
558 | |||
557 | if exception and (id(exception[1]) not in chained_exc_ids): |
|
559 | if exception and (id(exception[1]) not in chained_exc_ids): | |
558 | chained_exception_message = ( |
|
560 | chained_exception_message = ( | |
559 | self.prepare_chained_exception_message(evalue.__cause__)[0] |
|
561 | self.prepare_chained_exception_message(evalue.__cause__)[0] | |
560 | if evalue is not None |
|
562 | if evalue is not None | |
561 | else "" |
|
563 | else "" | |
562 | ) |
|
564 | ) | |
563 | etype, evalue, etb = exception |
|
565 | etype, evalue, etb = exception | |
564 | # Trace exception to avoid infinite 'cause' loop |
|
566 | # Trace exception to avoid infinite 'cause' loop | |
565 | chained_exc_ids.add(id(exception[1])) |
|
567 | chained_exc_ids.add(id(exception[1])) | |
566 | chained_exceptions_tb_offset = 0 |
|
568 | chained_exceptions_tb_offset = 0 | |
567 | out_list = ( |
|
569 | out_list = ( | |
568 | self.structured_traceback( |
|
570 | self.structured_traceback( | |
569 | etype, |
|
571 | etype, | |
570 | evalue, |
|
572 | evalue, | |
571 | (etb, chained_exc_ids), # type: ignore |
|
573 | (etb, chained_exc_ids), # type: ignore | |
572 | chained_exceptions_tb_offset, |
|
574 | chained_exceptions_tb_offset, | |
573 | context, |
|
575 | context, | |
|
576 | ) | |||
|
577 | + chained_exception_message | |||
|
578 | + out_list | |||
574 | ) |
|
579 | ) | |
575 | + chained_exception_message |
|
|||
576 | + out_list) |
|
|||
577 |
|
580 | |||
578 | return out_list |
|
581 | return out_list | |
579 |
|
582 |
General Comments 0
You need to be logged in to leave comments.
Login now