##// END OF EJS Templates
Show PEP-678 notes in ultratb (Plain), add tests
Zac Hatfield-Dodds -
Show More
@@ -0,0 +1,5 b''
1 Support for PEP-678 Exception Notes
2 -----------------------------------
3
4 Ultratb now shows :pep:`678` notes, improving your debugging experience on
5 Python 3.11+ or with libraries such as Pytest and Hypothesis.
@@ -363,6 +363,29 b' def r3o2():'
363 ip.run_cell("r3o2()")
363 ip.run_cell("r3o2()")
364
364
365
365
366 class PEP678NotesReportingTest(unittest.TestCase):
367 ERROR_WITH_NOTE = """
368 try:
369 raise AssertionError("Message")
370 except Exception as e:
371 try:
372 e.add_note("This is a PEP-678 note.")
373 except AttributeError: # Python <= 3.10
374 e.__notes__ = ("This is a PEP-678 note.",)
375 raise
376 """
377
378 def test_verbose_reports_notes(self):
379 with tt.AssertPrints(["AssertionError", "Message", "This is a PEP-678 note."]):
380 ip.run_cell(self.ERROR_WITH_NOTE)
381
382 def test_plain_reports_notes(self):
383 with tt.AssertPrints(["AssertionError", "Message", "This is a PEP-678 note."]):
384 ip.run_cell("%xmode Plain")
385 ip.run_cell(self.ERROR_WITH_NOTE)
386 ip.run_cell("%xmode Verbose")
387
388
366 #----------------------------------------------------------------------------
389 #----------------------------------------------------------------------------
367
390
368 # module testing (minimal)
391 # module testing (minimal)
@@ -686,6 +686,9 b' class ListTB(TBTools):'
686 else:
686 else:
687 list.append('%s\n' % stype)
687 list.append('%s\n' % stype)
688
688
689 # PEP-678 notes
690 list.extend(f"{x}\n" for x in getattr(value, "__notes__", []))
691
689 # sync with user hooks
692 # sync with user hooks
690 if have_filedata:
693 if have_filedata:
691 ipinst = get_ipython()
694 ipinst = get_ipython()
General Comments 0
You need to be logged in to leave comments. Login now