Author lisroach
Recipients ezio.melotti, lisroach, michael.foord, xtreak
Date 2019-09-10.14:42:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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

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:41lisroachsetrecipients: + lisroach, ezio.melotti, michael.foord, xtreak
2019-09-10 14:42:41lisroachsetmessageid: <>
2019-09-10 14:42:41lisroachlinkissue38093 messages
2019-09-10 14:42:40lisroachcreate