[issue17013] Allow waiting on a mock

Ilya Kulakov report at bugs.python.org
Mon Nov 18 14:03:46 EST 2019


Ilya Kulakov <kulakov.ilya at gmail.com> added the comment:

I have submitted an alternative implementation of this feature heavily inspired by _AwaitEvent I wrote for asynctest [0]. 

There was recently an interest from the community towards asynctest to the point that got some of its measures merged into CPython [1].

The key features of my implementation [2]:

- Gives meaning to the existing Mock.called property, otherwise not much useful
- Does not require end users to do anything: change is automatically available in every Mock (and any subclass of mock that does not override `called`)
- Use of conditionals provides API that allows much richer extension: instead of hardcoding conditions as events it allows to wait until arbitrary predicate becomes true
- Utilizes existing semantics of python conditionals (both asyncio and threading)

Accepting this PR will allow me to bring _AwaitEvent thereby completing mock.py with waiting mechanics with identical semantics for both threading-based and asyncio-based cases.


0: https://github.com/Martiusweb/asynctest/blob/4b1284d6bab1ae90a6e8d88b882413ebbb7e5dce/asynctest/mock.py#L428
1: https://github.com/python/cpython/pull/9296
2: https://github.com/python/cpython/pull/17133

----------
nosy: +Kentzo

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue17013>
_______________________________________


More information about the Python-bugs-list mailing list