We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
to your account
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
assignee = 'https://github.com/lisroach'
closed_at = <Date 2019-09-30.04:22:17.343>
created_at = <Date 2019-09-10.14:42:41.155>
labels = ['type-bug', '3.8', '3.9']
title = "Update MagicMock __aenter__ and __aexit__ to return AsyncMock's"
updated_at = <Date 2019-09-30.04:22:17.343>
user = 'https://github.com/lisroach'
activity = <Date 2019-09-30.04:22:17.343>
actor = 'lisroach'
assignee = 'lisroach'
closed = True
closed_date = <Date 2019-09-30.04:22:17.343>
closer = 'lisroach'
components = 
creation = <Date 2019-09-10.14:42:41.155>
creator = 'lisroach'
dependencies = 
files = 
hgrepos = 
issue_num = 38093
keywords = ['patch']
message_count = 3.0
messages = ['351682', '352829', '352928']
nosy_count = 5.0
nosy_names = ['ezio.melotti', 'michael.foord', 'matrixise', 'lisroach', 'xtreak']
pr_nums = ['15947', '16299']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue38093'
versions = ['Python 3.8', 'Python 3.9']
The text was updated successfully, but these errors were encountered:
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.
Sorry, something went wrong.
New changeset 8b03f94 by Lisa Roach in branch 'master':
bpo-38093: Correctly returns AsyncMock for async subclasses. (GH-15947)
New changeset 865bb68 by Stéphane Wirtel (Lisa Roach) in branch '3.8':
[3.8] bpo-38093: Correctly returns AsyncMock for async subclasses. (GH-15947) (GH-16299)
No branches or pull requests