[issue26467] Add async magic method support to unittest.mock.Mock

Yusuke Tsutsumi report at bugs.python.org
Sun Jun 5 17:51:27 EDT 2016


Yusuke Tsutsumi added the comment:

Taking a look at the code, this may require a bit more discussion.

Mock's classes create copies of themselves when an attribute is accessed. As such, I can't just add __aexit__ and have it generate a different mock type entirely, unless I know exactly what an async variant of this mock is.

If there was a way to specifically provide a function for asynchronous situations, like __acall__, that would make this a lot easier as well.

Anyway, my proposal now is:

create new classes MockAsync and MagicMockAsync, and have MockAsync and MagicMockAsync implement the __aexit__ and __aenter__ methods.

How is that as an approach?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26467>
_______________________________________


More information about the Python-bugs-list mailing list