[New-bugs-announce] [issue17013] Allow waiting on a mock

Antoine Pitrou report at bugs.python.org
Tue Jan 22 13:15:47 CET 2013


New submission from Antoine Pitrou:

In non-trivial tests, you may want to wait for a method to be called in another thread. This is a case where unittest.mock currently doesn't help. It would be nice to be able to write:

  myobj.some_method = Mock(side_effect=myobj.some_method)
  # launch some thread
  myobj.some_method.wait_until_called()

And perhaps

  myobj.some_method.wait_until_called_with(...)

(with an optional timeout?)

If we don't want every Mock object to embed a threading.Event, perhaps there could be a ThreadedMock subclass?
Or perhaps even:

  WaitableMock(..., event_class=threading.Event)

so that people can pass multiprocessing.Event if they want to wait on the mock from another process?

----------
components: Library (Lib)
messages: 180377
nosy: michael.foord, pitrou
priority: normal
severity: normal
status: open
title: Allow waiting on a mock
type: enhancement
versions: Python 3.4

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


More information about the New-bugs-announce mailing list