[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2021-04-11 Thread Matthew Suozzo
Change by Matthew Suozzo : -- pull_requests: +24081 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/25347 ___ Python tracker ___

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2021-04-10 Thread Gregory P. Smith
Change by Gregory P. Smith : -- resolution: fixed -> stage: resolved -> needs patch status: closed -> open ___ Python tracker ___

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2021-04-09 Thread Matthew Suozzo
Matthew Suozzo added the comment: I don't think this was actually fixed for the create_autospec case. create_autospec still uses the only is_async_func check to enable use of AsyncMock and that still does a __code__ check. There was a test submitted to check this case but the test itself

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-09-10 Thread miss-islington
miss-islington added the comment: New changeset c3008dd480d645678409273eecbfd24bbc9669d7 by Miss Islington (bot) in branch '3.8': bpo-37251: Removes __code__ check from _is_async_obj. (GH-15830) https://github.com/python/cpython/commit/c3008dd480d645678409273eecbfd24bbc9669d7 --

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-09-10 Thread Lisa Roach
Change by Lisa Roach : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-09-10 Thread Lisa Roach
Lisa Roach added the comment: New changeset f1a297acb60b88917712450ebd3cfa707e6efd6b by Lisa Roach in branch 'master': bpo-37251: Removes __code__ check from _is_async_obj. (GH-15830) https://github.com/python/cpython/commit/f1a297acb60b88917712450ebd3cfa707e6efd6b --

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-09-10 Thread miss-islington
Change by miss-islington : -- pull_requests: +15482 pull_request: https://github.com/python/cpython/pull/15837 ___ Python tracker ___

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-09-10 Thread Lisa Roach
Change by Lisa Roach : -- pull_requests: +15476 pull_request: https://github.com/python/cpython/pull/15830 ___ Python tracker ___

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-09-09 Thread Lisa Roach
Lisa Roach added the comment: I made a new branch with the changes I am suggesting here to try to be more clear: https://github.com/lisroach/cpython/tree/issue37251 What do you think? -- ___ Python tracker

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-25 Thread Lisa Roach
Lisa Roach added the comment: 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

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-20 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: > BUT I think removing the `if getattr(obj, '__code__', None)` from > `_is_async_obj` actually makes this work correctly. It is possible for a > coroutine object to not have a __code__, but I don't think it is possible for > a coroutine function

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-19 Thread Lisa Roach
Lisa Roach added the comment: Thanks for the patch! To answer your question, I do not think we can remove _is_async_func in favor of _is_async_obj, _is_async_obj will evaluate to True in cases where _is_async_func would not. For example: >>> class NewCoroutine(Awaitable): ... def

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-15 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I created PR to ensure the __code__ object is checked to be a CodeType and converted the report to a unittest. I also found a similar function _is_async_func [0] which also seems to perform similar check but is used only in create_autospec.

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-15 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- keywords: +patch pull_requests: +13967 stage: -> patch review pull_request: https://github.com/python/cpython/pull/14117 ___ Python tracker

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-12 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I will wait for a couple of days for suggestions and will raise a PR to check for __code__ to be a CodeType. Thanks. -- ___ Python tracker

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-12 Thread Lisa Roach
Lisa Roach added the comment: Following up from xtreak's proposal (https://github.com/python/cpython/pull/9296) I think checking if __code__ is actually a CodeType is a good idea. It's simple and doesn't change any other functionality in an unwanted way. --

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-12 Thread Miro Hrončok
Change by Miro Hrončok : -- nosy: +hroncok ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-12 Thread Mario Corchero
Change by Mario Corchero : -- nosy: +mariocj89 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-12 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +lisroach, xtreak ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2019-06-12 Thread Jeremy Cline
New submission from Jeremy Cline : This is related to the new AsyncMock[0] class in Python 3.8b1. A simple reproducer is: from unittest import mock mock_obj = mock.MagicMock() mock_obj.mock_func = mock.MagicMock(spec=lambda x: x) with mock.patch.object(mock_obj, "mock_func") as nested: