Skip to content

Commit 9d60706

Browse files
tirkarthizware
authored andcommitted
bpo-37212: Preserve keyword argument order in unittest.mock.call and error messages (pythonGH-14310)
1 parent 63c98ed commit 9d60706

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/unittest/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ def _format_call_signature(name, args, kwargs):
23202320
formatted_args = ''
23212321
args_string = ', '.join([repr(arg) for arg in args])
23222322
kwargs_string = ', '.join([
2323-
'%s=%r' % (key, value) for key, value in sorted(kwargs.items())
2323+
'%s=%r' % (key, value) for key, value in kwargs.items()
23242324
])
23252325
if args_string:
23262326
formatted_args = args_string

Lib/unittest/test/testmock/testmock.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,11 +1571,11 @@ def test_assert_called_once_message_not_called(self):
15711571
m.assert_called_once()
15721572
self.assertNotIn("Calls:", str(e.exception))
15731573

1574-
#Issue21256 printout of keyword args should be in deterministic order
1575-
def test_sorted_call_signature(self):
1574+
#Issue37212 printout of keyword args now preserves the original order
1575+
def test_ordered_call_signature(self):
15761576
m = Mock()
15771577
m.hello(name='hello', daddy='hero')
1578-
text = "call(daddy='hero', name='hello')"
1578+
text = "call(name='hello', daddy='hero')"
15791579
self.assertEqual(repr(m.hello.call_args), text)
15801580

15811581
#Issue21270 overrides tuple methods for mock.call objects
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`unittest.mock.call` now preserves the order of keyword arguments in
2+
repr output. Patch by Karthikeyan Singaravelan.

0 commit comments

Comments
 (0)