summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/testmock/testasync.py
diff options
context:
space:
mode:
authorSamuel Freilich <sfreilich@google.com>2019-09-24 22:04:29 (GMT)
committerGregory P. Smith <greg@krypto.org>2019-09-24 22:04:29 (GMT)
commit2180f6b058effbf49ec819f7cedbe76ddd4b700c (patch)
tree1f2962f22d5d1cfb38da125e8e3ec2bd200c5ac1 /Lib/unittest/test/testmock/testasync.py
parentb5a7a4f0c20717a4c92c371583b5521b83f40f32 (diff)
downloadcpython-2180f6b058effbf49ec819f7cedbe76ddd4b700c.zip
cpython-2180f6b058effbf49ec819f7cedbe76ddd4b700c.tar.gz
cpython-2180f6b058effbf49ec819f7cedbe76ddd4b700c.tar.bz2
bpo-36871: Avoid duplicated 'Actual:' in assertion message (GH-16361)
Fixes an issue caught after merge of PR 16005. Tightened test assertions to check the entire assertion message.
Diffstat (limited to 'Lib/unittest/test/testmock/testasync.py')
-rw-r--r--Lib/unittest/test/testmock/testasync.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py
index f951526..fde1e4a 100644
--- a/Lib/unittest/test/testmock/testasync.py
+++ b/Lib/unittest/test/testmock/testasync.py
@@ -892,21 +892,28 @@ class AsyncMockAssert(unittest.TestCase):
self.mock.assert_not_awaited()
def test_assert_has_awaits_not_matching_spec_error(self):
- async def f(): pass
+ async def f(x=None): pass
- mock = AsyncMock(spec=f)
+ self.mock = AsyncMock(spec=f)
+ asyncio.run(self._runnable_test(1))
with self.assertRaisesRegex(
AssertionError,
- re.escape('Awaits not found.\nExpected:')) as cm:
- mock.assert_has_awaits([call()])
+ '^{}$'.format(
+ re.escape('Awaits not found.\n'
+ 'Expected: [call()]\n'
+ 'Actual: [call(1)]'))) as cm:
+ self.mock.assert_has_awaits([call()])
self.assertIsNone(cm.exception.__cause__)
with self.assertRaisesRegex(
AssertionError,
- re.escape('Error processing expected awaits.\n'
- "Errors: [None, TypeError('too many positional "
- "arguments')]\n"
- 'Expected:')) as cm:
- mock.assert_has_awaits([call(), call('wrong')])
+ '^{}$'.format(
+ re.escape(
+ 'Error processing expected awaits.\n'
+ "Errors: [None, TypeError('too many positional "
+ "arguments')]\n"
+ 'Expected: [call(), call(1, 2)]\n'
+ 'Actual: [call(1)]'))) as cm:
+ self.mock.assert_has_awaits([call(), call(1, 2)])
self.assertIsInstance(cm.exception.__cause__, TypeError)