Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:
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. ---------- components: +Library (Lib) -Tests nosy: +cjw296, lisroach, mariocj89, michael.foord versions: +Python 3.10 -Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43371> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com