From 37a6f26d648eea576a13a19e023ab78697522f61 Mon Sep 17 00:00:00 2001 From: David Airapetyan Date: Mon, 9 Jul 2018 13:02:00 -0400 Subject: [PATCH 1/4] Improving error reporting when assert_has_calls fails --- Lib/unittest/mock.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 19dabddc7dfcc4..b7a87cd6f01af7 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -862,7 +862,8 @@ def assert_has_calls(self, calls, any_order=False): not_found.append(kall) if not_found: raise AssertionError( - '%r not all found in call list' % (tuple(not_found),) + '%r not all found in call list: %r' % (tuple(not_found), + all_calls) ) from cause From d3e1799d784d51acb65cee5bd413d1eb4bba9cce Mon Sep 17 00:00:00 2001 From: David Airapetyan Date: Tue, 10 Jul 2018 18:55:59 -0400 Subject: [PATCH 2/4] Adding news --- Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst 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 00000000000000..7c0d317b4e52de --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst @@ -0,0 +1 @@ +Improving error reporting when assert_has_calls fails From e285e5171fa714e81e871e259da3ee5ae0233071 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 17 Aug 2018 10:44:29 -0700 Subject: [PATCH 3/4] improve error message based on review comments. --- Lib/unittest/mock.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index b7a87cd6f01af7..db1e642c00b7f9 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -862,8 +862,9 @@ def assert_has_calls(self, calls, any_order=False): not_found.append(kall) if not_found: raise AssertionError( - '%r not all found in call list: %r' % (tuple(not_found), - all_calls) + '%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 From c5bf0495ba891277e928bda6e433a7bbe73132d6 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 17 Aug 2018 11:22:44 -0700 Subject: [PATCH 4/4] news entry wordsmithing --- Misc/NEWS.d/next/Tests/2018-07-10-18-53-46.bpo-0.UBQJBc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 7c0d317b4e52de..9d82677686bdfd 100644 --- 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 @@ -1 +1 @@ -Improving error reporting when assert_has_calls fails +Improved an error message when mock assert_has_calls fails.