bpo-37015: Ensure tasks created by _accept_connection2 due to AsyncMock are completed#13661
bpo-37015: Ensure tasks created by _accept_connection2 due to AsyncMock are completed#13661miss-islington merged 3 commits intopython:masterfrom
Conversation
|
The other way to solve this would be to remove Command to reproduce the warnings : |
| mock_obj = mock.patch.object | ||
| with mock_obj(self.loop, '_accept_connection2') as accept2_mock: | ||
| with mock_obj(self.loop, '_accept_connection2', | ||
| new=mock.MagicMock()) as accept2_mock: |
There was a problem hiding this comment.
Interesting! I usually use new for created objects and new_callable when I want a different mock type.
There was a problem hiding this comment.
This change in behavior has to be documented as noted in the tracker. Currently there is below text where MagicMock is documented as the target type but that changed in 3.8 with AsyncMock for async functions and MagicMock for normal functions when new is omitted in mock.patch.
https://docs.python.org/3/library/unittest.mock.html#patch
If new is omitted, then the target is replaced with a MagicMock
Please do it. Double mocking for both P.S. |
|
You're welcome @asvetlov . I have made the requested changes to make sure only Thanks |
…ck are completed (pythonGH-13661) From 3.8 async functions used with mock.patch return an `AsyncMock`. `_accept_connection2` is an async function where create_task is also mocked. Don't mock `create_task` so that tasks are created out of coroutine returned by `AsyncMock` and the tasks are completed. https://bugs.python.org/issue37015
From 3.8 async functions used with mock.patch return an
AsyncMock._accept_connection2is an async function where create_task is also mocked. Don't mockcreate_taskso that tasks are created out of coroutine returned byAsyncMockand the tasks are completed.https://bugs.python.org/issue37015