Skip to content

Commit 7e15b35

Browse files
committed
gh-156460: Test synchronous callable side effects
1 parent f5903c8 commit 7e15b35

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lib/test/test_unittest/testmock/testasync.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,15 @@ async def __call__(self, var):
477477
result = await mock(5)
478478
self.assertEqual(result, 6)
479479

480+
async def test_add_side_effect_sync_callable(self):
481+
class SyncCallable:
482+
def __call__(self, var):
483+
return var + 1
484+
485+
mock = AsyncMock(side_effect=SyncCallable())
486+
result = await mock(5)
487+
self.assertEqual(result, 6)
488+
480489
async def test_add_side_effect_normal_function(self):
481490
def addition(var):
482491
return var + 1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Await async callable objects used as the ``side_effect`` of
1+
Correctly handle async callable objects used as the ``side_effect`` of
22
:class:`unittest.mock.AsyncMock`.

0 commit comments

Comments
 (0)