-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-37015: Ensure tasks created by _accept_connection2 due to AsyncMock are completed #13661
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…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_connection2
is an async function where create_task is also mocked. Don't mockcreate_task
so that tasks are created out of coroutine returned byAsyncMock
and the tasks are completed.https://bugs.python.org/issue37015