Message346583
Yes, sorry I wasn't clear, I was thinking about the functions and testing without your PR. I think removing the __code__ object (or working around it) is the correct way to go, but just removing it wouldn't solve this particular problem.
"If I understand the awaitable examples correctly, mocking the obj which is an Awaitable should be returning an AsyncMock. But obj doesn't contain __code__ and hence check for inspect.isawaitable is never done causing _is_async_obj(obj) to return False and subsequently it's patched with MagicMock."
Exactly! This is why I think technically removing the __code__ check is correct. Probably removing the __code__ attribute for any AsyncMock that is mocking an async object and not an async function is best, but I don't know how I would do that.
I may also be misunderstanding some asyncio concepts, that is just what I observed :)
What if instead of checking for the __code__ object at all we check if there it is a Mock object (excluding AsyncMock):
def _is_async_obj(obj):
sync_mocks = [MagicMock, Mock, PropertyMock, NonCallableMock, NonCallableMagicMock]
if (any(isinstance(obj, sync_mock) for sync_mock in sync_mocks)
and not isinstance(obj, AsyncMock)):
return False
return asyncio.iscoroutinefunction(obj) or inspect.isawaitable(obj) |
|
Date |
User |
Action |
Args |
2019-06-26 04:14:59 | lisroach | set | recipients:
+ lisroach, hroncok, mariocj89, xtreak, jcline |
2019-06-26 04:14:59 | lisroach | set | messageid: <1561522499.31.0.401099021636.issue37251@roundup.psfhosted.org> |
2019-06-26 04:14:59 | lisroach | link | issue37251 messages |
2019-06-26 04:14:58 | lisroach | create | |
|