Message367419
aentering a MagicMock() results in an AsyncMock which behaves differently than I expected:
```
python3.9 -m asyncio
asyncio REPL 3.9.0a5 (default, Apr 18 2020, 00:00:31)
[GCC 9.3.0] on linux
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> from unittest import mock
>>> with mock.MagicMock() as m:
... with m.foo() as u:
... u.hello()
...
<MagicMock name='mock.__enter__().foo().__enter__().hello()' id='140670894620048'>
>>> async with mock.MagicMock() as m:
... async with m.foo() as u:
... u.hello()
...
<console>:2: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "/usr/lib/python3.9/concurrent/futures/_base.py", line 439, in result
return self.__get_result()
File "/usr/lib/python3.9/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "<console>", line 2, in <module>
AttributeError: __aenter__
```
This is annoying for mocking database interfaces like
```
async def update_users(db, user):
async with db.connection() as conn:
async with conn.transaction() as tx:
...
``` |
|
Date |
User |
Action |
Args |
2020-04-27 13:33:28 | graingert | set | recipients:
+ graingert, asvetlov, yselivanov |
2020-04-27 13:33:28 | graingert | set | messageid: <1587994408.9.0.812209740883.issue40406@roundup.psfhosted.org> |
2020-04-27 13:33:28 | graingert | link | issue40406 messages |
2020-04-27 13:33:28 | graingert | create | |
|