mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
gh-106300: Improve assertRaises(Exception) usages in tests (GH-106302)
This commit is contained in:
parent
80b9b3a517
commit
6e6a4cd523
7 changed files with 20 additions and 12 deletions
|
|
@ -116,10 +116,13 @@ class TestMailbox(TestBase):
|
|||
self.assertMailboxEmpty()
|
||||
|
||||
def test_add_that_raises_leaves_mailbox_empty(self):
|
||||
class CustomError(Exception): ...
|
||||
exc_msg = "a fake error"
|
||||
|
||||
def raiser(*args, **kw):
|
||||
raise Exception("a fake error")
|
||||
raise CustomError(exc_msg)
|
||||
support.patch(self, email.generator.BytesGenerator, 'flatten', raiser)
|
||||
with self.assertRaises(Exception):
|
||||
with self.assertRaisesRegex(CustomError, exc_msg):
|
||||
self._box.add(email.message_from_string("From: Alphöso"))
|
||||
self.assertEqual(len(self._box), 0)
|
||||
self._box.close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue