summaryrefslogtreecommitdiff
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index b1ab8631a4..2b9e7f14a7 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -895,13 +895,20 @@ class NonCallableMock(Base):
If `any_order` is True then the calls can be in any order, but
they must all appear in `mock_calls`."""
expected = [self._call_matcher(c) for c in calls]
- cause = expected if isinstance(expected, Exception) else None
+ cause = next((e for e in expected if isinstance(e, Exception)), None)
all_calls = _CallList(self._call_matcher(c) for c in self.mock_calls)
if not any_order:
if expected not in all_calls:
+ if cause is None:
+ problem = 'Calls not found.'
+ else:
+ problem = ('Error processing expected calls.\n'
+ 'Errors: {}').format(
+ [e if isinstance(e, Exception) else None
+ for e in expected])
raise AssertionError(
- 'Calls not found.\nExpected: %r\n'
- 'Actual: %r' % (_CallList(calls), self.mock_calls)
+ '%s\nExpected: %r\nActual: %r' % (
+ problem, _CallList(calls), self.mock_calls)
) from cause
return