bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)

Also refactor the call recording imolementation and add some notes
about its limitations.
This commit is contained in:
Chris Withers 2018-12-03 21:31:37 +00:00 committed by GitHub
parent 3bc0ebab17
commit 8ca0fa9d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 125 additions and 24 deletions

View file

@ -702,6 +702,19 @@ the *new_callable* argument to :func:`patch`.
unpacked as tuples to get at the individual arguments. See
:ref:`calls as tuples <calls-as-tuples>`.
.. note::
The way :attr:`mock_calls` are recorded means that where nested
calls are made, the parameters of ancestor calls are not recorded
and so will always compare equal:
>>> mock = MagicMock()
>>> mock.top(a=3).bottom()
<MagicMock name='mock.top().bottom()' id='...'>
>>> mock.mock_calls
[call.top(a=3), call.top().bottom()]
>>> mock.mock_calls[-1] == call.top(a=-1).bottom()
True
.. attribute:: __class__