gh-106300: Improve assertRaises(Exception) usages in tests (GH-106302)

This commit is contained in:
Nikita Sobolev 2023-07-07 23:42:40 +03:00 committed by GitHub
parent 80b9b3a517
commit 6e6a4cd523
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 12 deletions

View file

@ -459,9 +459,10 @@ class AsyncArguments(IsolatedAsyncioTestCase):
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):