[3.11] gh-106300: Improve assertRaises(Exception) usages in tests (GH-106302). (GH-106545)

(cherry picked from commit 6e6a4cd523)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Serhiy Storchaka 2023-07-08 11:22:33 +03:00 committed by GitHub
parent 1931c2a438
commit 6cd08a566f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 12 deletions

View file

@ -427,9 +427,10 @@ async def addition(self, var): pass
self.assertEqual(output, 10)
async def test_add_side_effect_exception(self):
class CustomError(Exception): pass
async def addition(var): pass
mock = AsyncMock(addition, side_effect=Exception('err'))
with self.assertRaises(Exception):
mock = AsyncMock(addition, side_effect=CustomError('side-effect'))
with self.assertRaisesRegex(CustomError, 'side-effect'):
await mock(5)
async def test_add_side_effect_coroutine(self):