Message388758
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. |
|
Date |
User |
Action |
Args |
2021-03-15 18:47:50 | xtreak | set | recipients:
+ xtreak, cjw296, michael.foord, lisroach, corona10, mariocj89, dmitriy.mironiyk, kamilturek |
2021-03-15 18:47:49 | xtreak | set | messageid: <1615834069.96.0.927602443204.issue43371@roundup.psfhosted.org> |
2021-03-15 18:47:49 | xtreak | link | issue43371 messages |
2021-03-15 18:47:49 | xtreak | create | |
|