Skip to content

Commit

Permalink
bpo-37212: Preserve keyword argument order in unittest.mock.call and …
Browse files Browse the repository at this point in the history
…error messages (GH-14310)
  • Loading branch information
tirkarthi authored and zware committed Sep 9, 2019
1 parent 63c98ed commit 9d60706
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Lib/unittest/mock.py
Expand Up @@ -2320,7 +2320,7 @@ def _format_call_signature(name, args, kwargs):
formatted_args = ''
args_string = ', '.join([repr(arg) for arg in args])
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:
formatted_args = args_string
Expand Down
6 changes: 3 additions & 3 deletions Lib/unittest/test/testmock/testmock.py
Expand Up @@ -1571,11 +1571,11 @@ def test_assert_called_once_message_not_called(self):
m.assert_called_once()
self.assertNotIn("Calls:", str(e.exception))

#Issue21256 printout of keyword args should be in deterministic order
def test_sorted_call_signature(self):
#Issue37212 printout of keyword args now preserves the original order
def test_ordered_call_signature(self):
m = Mock()
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)

#Issue21270 overrides tuple methods for mock.call objects
Expand Down
@@ -0,0 +1,2 @@
:func:`unittest.mock.call` now preserves the order of keyword arguments in
repr output. Patch by Karthikeyan Singaravelan.

0 comments on commit 9d60706

Please sign in to comment.