Message363817
Thanks for the report. At [0] self.call_args is used. This value is always the last call. So when the object is awaited it will be always the last call object and gets appended. The id of the call objects remain the same. The fix would be to construct the call object with args and kwargs in asynchronous definition of _execute_mock_call like [1]. This would need tests too. It seems there is only test for one await call and assertion over await_args_list. Having different args and kwargs with multiple await to assert await_args_list would help here. In synchronous case the call object is eagerly appended so it won't be an issue.
[0] https://github.com/python/cpython/blob/8510f430781118d9b603c3a2f06945d6ebc5fe42/Lib/unittest/mock.py#L2174
[1] https://github.com/python/cpython/blob/8510f430781118d9b603c3a2f06945d6ebc5fe42/Lib/unittest/mock.py#L1106
A potential patch would be as below :
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 9e692981a2..20daf724c1 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2171,7 +2171,7 @@ class AsyncMockMixin(Base):
# This is nearly just like super(), except for special handling
# of coroutines
- _call = self.call_args
+ _call = _Call((args, kwargs), two=True)
self.await_count += 1
self.await_args = _call
self.await_args_list.append(_call) |
|
Date |
User |
Action |
Args |
2020-03-10 09:20:14 | xtreak | set | recipients:
+ xtreak, cjw296, michael.foord, asvetlov, yselivanov, lisroach, mariocj89, Mads Sejersen |
2020-03-10 09:20:14 | xtreak | set | messageid: <1583832014.22.0.607731044642.issue39915@roundup.psfhosted.org> |
2020-03-10 09:20:14 | xtreak | link | issue39915 messages |
2020-03-10 09:20:14 | xtreak | create | |
|