Message351682
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. |
|
Date |
User |
Action |
Args |
2019-09-10 14:42:41 | lisroach | set | recipients:
+ lisroach, ezio.melotti, michael.foord, xtreak |
2019-09-10 14:42:41 | lisroach | set | messageid: <1568126561.19.0.234964443085.issue38093@roundup.psfhosted.org> |
2019-09-10 14:42:41 | lisroach | link | issue38093 messages |
2019-09-10 14:42:40 | lisroach | create | |
|