mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-45607: Make it possible to enrich exception displays via setting their __note__ field (GH-29880)
This commit is contained in:
parent
d9301703fb
commit
5bb7ef2768
10 changed files with 183 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue