summaryrefslogtreecommitdiff
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 48379222c3..14e0f840d4 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1023,27 +1023,20 @@ class ExceptionTests(unittest.TestCase):
# The following line is included in the traceback report:
raise exc
- class BrokenRepr(BrokenDel):
- def __repr__(self):
- raise AttributeError("repr() is broken")
-
class BrokenExceptionDel:
def __del__(self):
exc = BrokenStrException()
# The following line is included in the traceback report:
raise exc
- for test_class in (BrokenDel, BrokenRepr, BrokenExceptionDel):
+ for test_class in (BrokenDel, BrokenExceptionDel):
with self.subTest(test_class):
obj = test_class()
with captured_stderr() as stderr:
del obj
report = stderr.getvalue()
self.assertIn("Exception ignored", report)
- if test_class is BrokenRepr:
- self.assertIn("<object repr() failed>", report)
- else:
- self.assertIn(test_class.__del__.__qualname__, report)
+ self.assertIn(test_class.__del__.__qualname__, report)
self.assertIn("test_exceptions.py", report)
self.assertIn("raise exc", report)
if test_class is BrokenExceptionDel:
@@ -1112,6 +1105,20 @@ class ImportErrorTests(unittest.TestCase):
with self.assertRaisesRegex(TypeError, msg):
ImportError('test', invalid='keyword', another=True)
+ def test_reset_attributes(self):
+ exc = ImportError('test', name='name', path='path')
+ self.assertEqual(exc.args, ('test',))
+ self.assertEqual(exc.msg, 'test')
+ self.assertEqual(exc.name, 'name')
+ self.assertEqual(exc.path, 'path')
+
+ # Reset not specified attributes
+ exc.__init__()
+ self.assertEqual(exc.args, ())
+ self.assertEqual(exc.msg, None)
+ self.assertEqual(exc.name, None)
+ self.assertEqual(exc.path, None)
+
def test_non_str_argument(self):
# Issue #15778
with check_warnings(('', BytesWarning), quiet=True):