bpo-45607: Make it possible to enrich exception displays via setting their __note__ field (GH-29880)

This commit is contained in:
Irit Katriel 2021-12-03 22:01:15 +00:00 committed by GitHub
parent d9301703fb
commit 5bb7ef2768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 183 additions and 5 deletions

View file

@ -516,6 +516,27 @@ class ExceptionTests(unittest.TestCase):
'pickled "%r", attribute "%s' %
(e, checkArgName))
def test_note(self):
for e in [BaseException(1), Exception(2), ValueError(3)]:
with self.subTest(e=e):
self.assertIsNone(e.__note__)
e.__note__ = "My Note"
self.assertEqual(e.__note__, "My Note")
with self.assertRaises(TypeError):
e.__note__ = 42
self.assertEqual(e.__note__, "My Note")
e.__note__ = "Your Note"
self.assertEqual(e.__note__, "Your Note")
with self.assertRaises(TypeError):
del e.__note__
self.assertEqual(e.__note__, "Your Note")
e.__note__ = None
self.assertIsNone(e.__note__)
def testWithTraceback(self):
try:
raise IndexError(4)