summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMehdi ABAAKOUK <sileht@sileht.net>2022-06-30 17:08:38 (GMT)
committerGitHub <noreply@github.com>2022-06-30 17:08:38 (GMT)
commit4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc (patch)
tree004df1f1a95ed6113b55ab0f92d3e66b405fd424 /Lib/unittest
parent639e35108bc8b2b880225862d3571277ad57648b (diff)
downloadcpython-4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc.zip
cpython-4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc.tar.gz
cpython-4261b6bffc0b8bb5c6d4d80578a81b7520f4aefc.tar.bz2
gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock (#94050)
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>
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 8262b71..cd46fea 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2175,6 +2175,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