[issue37015] Fix asyncio mock warnings

Karthikeyan Singaravelan report at bugs.python.org
Wed May 22 15:16:28 EDT 2019


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

I guess cause is at [0] . When there is no new value specified and with spec being None if mock.patch is used on an async object (original = _accept_connection2). Here original is an async object then AsyncMock is returned. 

Changing this causes test failures where patching AsyncClass.async_method now expects an AsyncMock but as per older behavior it returns MagicMock. I think it's a behavior that needs to be discussed as it differs from 3.7 and not sure if AsyncMock would always be awaited as seen in test_accept_connection_multiple.

[0] https://github.com/python/cpython/blob/b121f63155d8e3c7c42ab6122e36eaf7f5e9f7f5/Lib/unittest/mock.py#L1313

if spec is None and _is_async_obj(original):
    Klass = AsyncMock
else:
    Klass = MagicMock

----------
nosy: +lisroach, mariocj89

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37015>
_______________________________________


More information about the Python-bugs-list mailing list