This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients asvetlov, lisroach, mariocj89, xtreak
Date 2019-05-24.08:10:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1558685443.46.0.840828504017.issue37015@roundup.psfhosted.org>
In-reply-to
Content
This logic is present in create_autospec too at [0]. The behavior for patch seems to be documented at [1] which also needs to be updated to reflect that an AsyncMock by default is created instead of MagicMock if the target is an async function unlike 3.7. Probably also a versionchanged directive to note this if the current behavior is okay. Since it generates a RuntimeWarning I think it will be good if the behavior is decided before 3.8 beta 1.

> If new is omitted, then the target is replaced with a MagicMock. If patch() is used as a decorator and new is omitted, the created mock is passed in as an extra argument to the decorated function. If patch() is used as a context manager the created mock is returned by the context manager.

$ python3.7 -q
>>> import asyncio
>>> from unittest.mock import create_autospec
>>> loop = asyncio.get_event_loop()
>>> loop_mock = create_autospec(loop)
>>> loop_mock._accept_connection2
<MagicMock name='mock._accept_connection2' spec='method' id='4455012896'>

$ ./python.exe -q
>>> import asyncio
>>> from unittest.mock import create_autospec
>>> loop = asyncio.get_event_loop()
>>> loop_mock = create_autospec(loop)
>>> loop_mock._accept_connection2
<AsyncMock name='mock._accept_connection2' spec='method' id='4314046368'>

[0] https://github.com/python/cpython/blob/cccc11b38e5409861f4db345a4dd45dcc9ba470c/Lib/unittest/mock.py#L2564
[1] https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch
History
Date User Action Args
2019-05-24 08:10:43xtreaksetrecipients: + xtreak, asvetlov, lisroach, mariocj89
2019-05-24 08:10:43xtreaksetmessageid: <1558685443.46.0.840828504017.issue37015@roundup.psfhosted.org>
2019-05-24 08:10:43xtreaklinkissue37015 messages
2019-05-24 08:10:43xtreakcreate