summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-06-30 18:02:15 (GMT)
committerGitHub <noreply@github.com>2022-06-30 18:02:15 (GMT)
commit47f23b2d8a14a2f182375c840776eadfc371c726 (patch)
tree76ead06fbb8909c527a9438d7069c795b71ce87f /Lib/unittest
parentd915ed297804041c822a595c0f44e52a4c385302 (diff)
downloadcpython-47f23b2d8a14a2f182375c840776eadfc371c726.zip
cpython-47f23b2d8a14a2f182375c840776eadfc371c726.tar.gz
cpython-47f23b2d8a14a2f182375c840776eadfc371c726.tar.bz2
gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (GH-94050) (GH-94461)
The inspect version was not working with unittest.mock.AsyncMock. The fix introduces special-casing of AsyncMock in `inspect.iscoroutinefunction` equivalent to the one performed in `asyncio.iscoroutinefunction`. Co-authored-by: Ɓukasz Langa <lukasz@langa.pl> (cherry picked from commit 4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc) Co-authored-by: Mehdi ABAAKOUK <sileht@sileht.net>
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 7152f86..3f7185b 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2186,6 +2186,10 @@ class AsyncMockMixin(Base):
code_mock = NonCallableMock(spec_set=CodeType)
code_mock.co_flags = inspect.CO_COROUTINE
self.__dict__['__code__'] = code_mock
+ self.__dict__['__name__'] = 'AsyncMock'
+ self.__dict__['__defaults__'] = tuple()
+ self.__dict__['__kwdefaults__'] = {}
+ self.__dict__['__annotations__'] = None
async def _execute_mock_call(self, /, *args, **kwargs):
# This is nearly just like super(), except for special handling