mirror of
https://github.com/python/cpython.git
synced 2025-10-16 11:49:57 +00:00
bpo-37212: Preserve keyword argument order in unittest.mock.call and error messages (GH-14310)
This commit is contained in:
parent
63c98ed2d2
commit
9d607061c9
3 changed files with 6 additions and 4 deletions
|
@ -2320,7 +2320,7 @@ def _format_call_signature(name, args, kwargs):
|
||||||
formatted_args = ''
|
formatted_args = ''
|
||||||
args_string = ', '.join([repr(arg) for arg in args])
|
args_string = ', '.join([repr(arg) for arg in args])
|
||||||
kwargs_string = ', '.join([
|
kwargs_string = ', '.join([
|
||||||
'%s=%r' % (key, value) for key, value in sorted(kwargs.items())
|
'%s=%r' % (key, value) for key, value in kwargs.items()
|
||||||
])
|
])
|
||||||
if args_string:
|
if args_string:
|
||||||
formatted_args = args_string
|
formatted_args = args_string
|
||||||
|
|
|
@ -1571,11 +1571,11 @@ class MockTest(unittest.TestCase):
|
||||||
m.assert_called_once()
|
m.assert_called_once()
|
||||||
self.assertNotIn("Calls:", str(e.exception))
|
self.assertNotIn("Calls:", str(e.exception))
|
||||||
|
|
||||||
#Issue21256 printout of keyword args should be in deterministic order
|
#Issue37212 printout of keyword args now preserves the original order
|
||||||
def test_sorted_call_signature(self):
|
def test_ordered_call_signature(self):
|
||||||
m = Mock()
|
m = Mock()
|
||||||
m.hello(name='hello', daddy='hero')
|
m.hello(name='hello', daddy='hero')
|
||||||
text = "call(daddy='hero', name='hello')"
|
text = "call(name='hello', daddy='hero')"
|
||||||
self.assertEqual(repr(m.hello.call_args), text)
|
self.assertEqual(repr(m.hello.call_args), text)
|
||||||
|
|
||||||
#Issue21270 overrides tuple methods for mock.call objects
|
#Issue21270 overrides tuple methods for mock.call objects
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
:func:`unittest.mock.call` now preserves the order of keyword arguments in
|
||||||
|
repr output. Patch by Karthikeyan Singaravelan.
|
Loading…
Add table
Add a link
Reference in a new issue