Skip to content

Commit

Permalink
gh-106300: Improve assertRaises(Exception) usages in tests (GH-106302)
Browse files Browse the repository at this point in the history
Backports: 6e6a4cd52332017b10c8d88fbbbfe015948093f4
Signed-off-by: Chris Withers <chris@simplistix.co.uk>
  • Loading branch information
sobolevn authored and cjw296 committed Jul 11, 2023
1 parent 9cbc589 commit 8d36bf4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mock/tests/testasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,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):
Expand Down

0 comments on commit 8d36bf4

Please sign in to comment.