From 8d36bf4cc5f86cb7cc0b60d7b9f2c9c5e53f7f37 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 7 Jul 2023 23:42:40 +0300 Subject: [PATCH] gh-106300: Improve `assertRaises(Exception)` usages in tests (GH-106302) Backports: 6e6a4cd52332017b10c8d88fbbbfe015948093f4 Signed-off-by: Chris Withers --- mock/tests/testasync.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mock/tests/testasync.py b/mock/tests/testasync.py index 7fd680f4..f21b9fa8 100644 --- a/mock/tests/testasync.py +++ b/mock/tests/testasync.py @@ -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):