This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients cjw296, corona10, dmitriy.mironiyk, kamilturek, lisroach, mariocj89, michael.foord, xtreak
Date 2021-03-15.18:47:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615834069.96.0.927602443204.issue43371@roundup.psfhosted.org>
In-reply-to
Content
https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_has_calls

> If any_order is false then the calls must be sequential. There can be extra calls before or after the specified calls.

One way to check that the calls appear in order even with extra calls in between since any_order=False expects the calls to be sequential is to use mock_calls which is a list and use index method. It's not very elegant.

>>> from unittest.mock import Mock, call
>>> m = Mock()
>>> m(1)
<Mock name='mock()' id='139845749964176'>
>>> m(2)
<Mock name='mock()' id='139845749964176'>
>>> m(3)
<Mock name='mock()' id='139845749964176'> 
>>> m.mock_calls.index(call(1))
0
>>> m.mock_calls.index(call(3))
2

> - Mock.assert_has_only_calls that always raise an error when mock has calls other than expected(not regarding any_order).

This sounds like a stricter version of assert_has_calls to ensure expected is matched without order with mock_calls and len(expected) == len(mock_calls)

I am not keen on changing behavior of assert_has_calls with any additional flags for compatibility but any additional helper should go in python 3.10 only. So I have updated the version.
History
Date User Action Args
2021-03-15 18:47:50xtreaksetrecipients: + xtreak, cjw296, michael.foord, lisroach, corona10, mariocj89, dmitriy.mironiyk, kamilturek
2021-03-15 18:47:49xtreaksetmessageid: <1615834069.96.0.927602443204.issue43371@roundup.psfhosted.org>
2021-03-15 18:47:49xtreaklinkissue43371 messages
2021-03-15 18:47:49xtreakcreate