From: davidair Date: Fri, 17 Aug 2018 19:09:58 +0000 (-0400) Subject: Improve error message when mock.assert_has_calls fails (GH-8205) X-Git-Tag: v3.8.0a1~1197 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b32da2fea1f077bb07a175f97ad8241e5605169;p=thirdparty%2FPython%2Fcpython.git Improve error message when mock.assert_has_calls fails (GH-8205) This makes the assertion error message more useful, aiding debugging. Thanks @davidair! --- diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 19dabddc7dfc..db1e642c00b7 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -862,7 +862,9 @@ class NonCallableMock(Base): not_found.append(kall) if not_found: raise AssertionError( - '%r not all found in call list' % (tuple(not_found),) + '%r does not contain all of %r in its call list, ' + 'found %r instead' % (self._mock_name or 'mock', + tuple(not_found), all_calls) ) from cause diff --git a/Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst b/Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst new file mode 100644 index 000000000000..9d82677686bd --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst @@ -0,0 +1 @@ +Improved an error message when mock assert_has_calls fails.