]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Improve error message when mock.assert_has_calls fails (GH-8205)
authordavidair <davidair@users.noreply.github.com>
Fri, 17 Aug 2018 19:09:58 +0000 (15:09 -0400)
committerGregory P. Smith <greg@krypto.org>
Fri, 17 Aug 2018 19:09:58 +0000 (12:09 -0700)
This makes the assertion error message more useful, aiding debugging.

Thanks @davidair!

Lib/unittest/mock.py
Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst [new file with mode: 0644]

index 19dabddc7dfcc4132cda3ae7060b0ae3a065ca3d..db1e642c00b7f9c8b86eb3c81b880b35b9851b33 100644 (file)
@@ -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 (file)
index 0000000..9d82677
--- /dev/null
@@ -0,0 +1 @@
+Improved an error message when mock assert_has_calls fails.