Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
_safe_super = super

def _is_async_obj(obj):
if getattr(obj, '__code__', None):
code = getattr(obj, '__code__', None)
if isinstance(code, CodeType):
return asyncio.iscoroutinefunction(obj) or inspect.isawaitable(obj)
else:
return False
Expand Down
7 changes: 7 additions & 0 deletions Lib/unittest/test/testmock/testasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ def test_is_child_AsyncMock(self):
self.assertIsInstance(mock.normal_method, MagicMock)
self.assertIsInstance(mock, MagicMock)

def test_magicmock_lambda_spec(self):
mock_obj = MagicMock()
mock_obj.mock_func = MagicMock(spec=lambda x: x)

with patch.object(mock_obj, "mock_func") as cm:
self.assertIsInstance(cm, MagicMock)


class AsyncArguments(unittest.TestCase):
def test_add_return_value(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`unittest.mock.MagicMock` with function as spec used as a spec to
:func:`unittest.mock.patch` should return a
:class:`unittest.mock.MagicMock`. Patch by Karthikeyan Singaravelan.