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.
Created on 2016年03月01日 22:51 by brett.cannon, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 9296 | merged | lisroach, 2018年09月14日 07:17 | |
| PR 17130 | merged | Ilya.Kulakov, 2019年11月12日 18:52 | |
| PR 17138 | merged | miss-islington, 2019年11月13日 02:33 | |
| Messages (12) | |||
|---|---|---|---|
| msg261092 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2016年03月01日 22:51 | |
Mock doesn't support stuff like __aexit__ which means you can't mock out something like an async context manager. |
|||
| msg267338 - (view) | Author: Yusuke Tsutsumi (tsutsumi) * | Date: 2016年06月04日 22:46 | |
I'm interested in taking this on. I'm considering for this approach, creating a new MagicProxy class specifically for async, and assigning __aexit__ and __aenter__ to those. The __call__ method itself has to be detected as asynchronous, and I don't believe it's possible for a __call__ to behave appropriately for both asynchronous and synchronous cases. |
|||
| msg267479 - (view) | Author: Yusuke Tsutsumi (tsutsumi) * | Date: 2016年06月05日 21:51 | |
Taking a look at the code, this may require a bit more discussion. Mock's classes create copies of themselves when an attribute is accessed. As such, I can't just add __aexit__ and have it generate a different mock type entirely, unless I know exactly what an async variant of this mock is. If there was a way to specifically provide a function for asynchronous situations, like __acall__, that would make this a lot easier as well. Anyway, my proposal now is: create new classes MockAsync and MagicMockAsync, and have MockAsync and MagicMockAsync implement the __aexit__ and __aenter__ methods. How is that as an approach? |
|||
| msg267569 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2016年06月06日 22:57 | |
There's also __aiter__, but it's semantics might be changing (issue #27243). Robert or Michael, any opinions on Yusuke's proposal? |
|||
| msg283657 - (view) | Author: Javier Domingo (txomon) | Date: 2016年12月20日 00:22 | |
I found this while trying to test an async context manager. This is a critical feature to enable migrations to async code, as the impossibility to test something properly is not acceptable in many environments. Implementing it in a way that __call__ returns an object capable of being coroutine or normal function would avoid having to implement Async specific Mocks, wouldn't it? I am not too confident, but would it be doable to have an implementation that depends on whether _is_coroutine is accessed or not? I don't like it, but I really don't like the fact that we need to patch different all the methods depending on whether they are coroutine or not. Obviously, having the __acall__ method would really help solving this issue. |
|||
| msg293644 - (view) | Author: Michał Bultrowicz (butla) * | Date: 2017年05月14日 10:53 | |
I guess that it's worth noting that the same problem is being talked about in an issue on the asynctest library: https://github.com/Martiusweb/asynctest/issues/29 |
|||
| msg333208 - (view) | Author: Dima Tisnek (Dima.Tisnek) * | Date: 2019年01月08日 04:16 | |
Perhaps it's possible to vendor asynctest mock in the same vein as `mock` found it's way into unittest?
The real power of `asynctest` is in constructs like:
with asynctest.mock.patch("module.Class", autospec=True):
...
Where mock instances know what methods are async.
|
|||
| msg342926 - (view) | Author: Lisa Roach (lisroach) * (Python committer) | Date: 2019年05月20日 16:19 | |
New changeset 77b3b7701a34ecf6316469e05b79bb91de2addfa by Lisa Roach in branch 'master': bpo-26467: Adds AsyncMock for asyncio Mock library support (GH-9296) https://github.com/python/cpython/commit/77b3b7701a34ecf6316469e05b79bb91de2addfa |
|||
| msg342929 - (view) | Author: Lisa Roach (lisroach) * (Python committer) | Date: 2019年05月20日 16:36 | |
Added and AsyncMock class which supports mocking async magic methods. |
|||
| msg356485 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2019年11月12日 19:43 | |
Adding Lisa to potentially add the PR from Ilya. |
|||
| msg356511 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2019年11月13日 02:33 | |
New changeset d6d6e2aa0249bb661541705335ddbb97a53d64c8 by Benjamin Peterson (Ilya Kulakov) in branch 'master': Add Ilya Kulakov to Misc/ACKS. (GH-17130) https://github.com/python/cpython/commit/d6d6e2aa0249bb661541705335ddbb97a53d64c8 |
|||
| msg356513 - (view) | Author: miss-islington (miss-islington) | Date: 2019年11月13日 02:40 | |
New changeset e5125f7b3b88d8d4814ed7bddbd4f34d24d763dd by Miss Islington (bot) in branch '3.8': Add Ilya Kulakov to Misc/ACKS. (GH-17130) https://github.com/python/cpython/commit/e5125f7b3b88d8d4814ed7bddbd4f34d24d763dd |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:28 | admin | set | github: 70654 |
| 2019年11月13日 02:40:34 | miss-islington | set | nosy:
+ miss-islington messages: + msg356513 |
| 2019年11月13日 02:33:34 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg356511 |
| 2019年11月13日 02:33:17 | miss-islington | set | pull_requests: + pull_request16648 |
| 2019年11月12日 19:43:16 | brett.cannon | set | assignee: lisroach messages: + msg356485 |
| 2019年11月12日 18:52:16 | Ilya.Kulakov | set | pull_requests: + pull_request16639 |
| 2019年05月20日 16:36:26 | lisroach | set | status: open -> closed messages: + msg342929 stage: patch review -> resolved |
| 2019年05月20日 16:19:58 | lisroach | set | nosy:
+ lisroach messages: + msg342926 |
| 2019年01月08日 05:02:00 | xtreak | set | nosy:
+ xtreak |
| 2019年01月08日 04:16:26 | Dima.Tisnek | set | nosy:
+ Dima.Tisnek messages: + msg333208 versions: + Python 3.8, - Python 3.6, Python 3.7 |
| 2018年10月10日 23:54:39 | yselivanov | set | nosy:
+ yselivanov |
| 2018年09月14日 07:17:42 | lisroach | set | keywords:
+ patch stage: test needed -> patch review pull_requests: + pull_request8725 |
| 2018年08月24日 00:28:36 | jmehnle | set | nosy:
+ jmehnle |
| 2017年11月04日 17:45:18 | yan12125 | set | nosy:
+ yan12125 |
| 2017年05月14日 10:53:17 | butla | set | nosy:
+ butla messages: + msg293644 |
| 2017年02月14日 09:38:38 | berker.peksag | set | nosy:
+ berker.peksag versions: + Python 3.7 |
| 2016年12月20日 00:22:47 | txomon | set | nosy:
+ txomon messages: + msg283657 |
| 2016年06月06日 22:57:03 | brett.cannon | set | nosy:
+ rbcollins messages: + msg267569 |
| 2016年06月05日 21:51:27 | tsutsumi | set | messages: + msg267479 |
| 2016年06月04日 22:46:43 | tsutsumi | set | nosy:
+ tsutsumi messages: + msg267338 |
| 2016年03月01日 22:51:46 | brett.cannon | create | |