Skip to content

bpo-39915: Ensure await_args_list is updated according to the order in which coroutines were awaited #18924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ async def _execute_mock_call(self, /, *args, **kwargs):
# 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)
Expand Down
11 changes: 11 additions & 0 deletions Lib/unittest/test/testmock/testasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ def inner():
mock.assert_awaited()
self.assertTrue(ran)

async def test_await_args_list_order(self):
async_mock = AsyncMock()
mock2 = async_mock(2)
mock1 = async_mock(1)
await mock1
await mock2
async_mock.assert_has_awaits([call(1), call(2)])
self.assertEqual(async_mock.await_args_list, [call(1), call(2)])
self.assertEqual(async_mock.call_args_list, [call(2), call(1)])


class AsyncMagicMethods(unittest.TestCase):
def test_async_magic_methods_return_async_mocks(self):
m_mock = MagicMock()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Ensure :attr:`unittest.mock.AsyncMock.await_args_list` has call objects in
the order of awaited arguments instead of using
:attr:`unittest.mock.Mock.call_args` which has the last value of the call.
Patch by Karthikeyan Singaravelan.