diff options
Diffstat (limited to 'Lib/unittest/test/testmock/testmock.py')
-rw-r--r-- | Lib/unittest/test/testmock/testmock.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py index 88807d71ccb..01bc4794446 100644 --- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py @@ -1436,23 +1436,30 @@ class MockTest(unittest.TestCase): mock.assert_has_calls(calls[:-1], any_order=True) def test_assert_has_calls_not_matching_spec_error(self): - def f(): pass + def f(x=None): pass mock = Mock(spec=f) + mock(1) with self.assertRaisesRegex( AssertionError, - re.escape('Calls not found.\nExpected:')) as cm: + '^{}$'.format( + re.escape('Calls not found.\n' + 'Expected: [call()]\n' + 'Actual: [call(1)]'))) as cm: mock.assert_has_calls([call()]) self.assertIsNone(cm.exception.__cause__) + with self.assertRaisesRegex( AssertionError, - re.escape('Error processing expected calls.\n' - "Errors: [None, TypeError('too many positional " - "arguments')]\n" - 'Expected:')) as cm: - mock.assert_has_calls([call(), call('wrong')]) + '^{}$'.format( + re.escape( + 'Error processing expected calls.\n' + "Errors: [None, TypeError('too many positional arguments')]\n" + "Expected: [call(), call(1, 2)]\n" + 'Actual: [call(1)]'))) as cm: + mock.assert_has_calls([call(), call(1, 2)]) self.assertIsInstance(cm.exception.__cause__, TypeError) def test_assert_any_call(self): |