New submission from Lisa Roach <lisaroac...@gmail.com>:
After a discussion with Michael, xtreak, and Ezio we've decided to try to make the process of mocking an async context manager slightly easier. Currently if you want to mock a context manager that is used like this: async with cm(): # note that cm is called here blah You need to mock cm as a MagicMock and set __aenter__ and __aexit__ return values directly because they do not exist on MagicMocks. Our first step to making this easier is setting the calculated return value of MagicMock __aenter__ and __aexit__ to be AsyncMock, which will make it so you do not need to set them specifically. A future improvement may be to create a ContextManagerMock directly that can take an async kwarg that would return a context manager with AsyncMocks for __aenter__ and __aexit__ automatically. ---------- assignee: lisroach messages: 351682 nosy: ezio.melotti, lisroach, michael.foord, xtreak priority: normal severity: normal stage: needs patch status: open title: Update MagicMock __aenter__ and __aexit__ to return AsyncMock's type: behavior versions: Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38093> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com