mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +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
|
@ -696,14 +696,16 @@ class TestEmailMessageBase:
|
|||
self.assertIsNone(part['Content-Disposition'])
|
||||
|
||||
class _TestSetRaisingContentManager:
|
||||
class CustomError(Exception):
|
||||
pass
|
||||
def set_content(self, msg, content, *args, **kw):
|
||||
raise Exception('test')
|
||||
raise self.CustomError('test')
|
||||
|
||||
def test_default_content_manager_for_add_comes_from_policy(self):
|
||||
cm = self._TestSetRaisingContentManager()
|
||||
m = self.message(policy=self.policy.clone(content_manager=cm))
|
||||
for method in ('add_related', 'add_alternative', 'add_attachment'):
|
||||
with self.assertRaises(Exception) as ar:
|
||||
with self.assertRaises(self._TestSetRaisingContentManager.CustomError) as ar:
|
||||
getattr(m, method)('')
|
||||
self.assertEqual(str(ar.exception), 'test')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue