diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-12-03 22:01:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-03 22:01:15 +0000 |
commit | 5bb7ef2768be5979b306e4c7552862b1746c251d (patch) | |
tree | 2c5d4d96a1e5bba8d0d918cc413d882f10308e63 /Lib/test/test_exceptions.py | |
parent | d9301703fb1086cafbd730c17e3d450a192485d6 (diff) | |
download | cpython-5bb7ef2768be5979b306e4c7552862b1746c251d.tar.gz cpython-5bb7ef2768be5979b306e4c7552862b1746c251d.zip |
bpo-45607: Make it possible to enrich exception displays via setting their __note__ field (GH-29880)
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index c6660043c80..e4b7b8f0a64 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -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) |