diff -r 8c8315bac6a8 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Sun Apr 20 09:45:00 2014 -0700 +++ b/Lib/unittest/mock.py Tue Apr 22 08:58:02 2014 +0530 @@ -1894,7 +1894,7 @@ formatted_args = '' args_string = ', '.join([repr(arg) for arg in args]) kwargs_string = ', '.join([ - '%s=%r' % (key, value) for key, value in kwargs.items() + '%s=%r' % (key, value) for key, value in sorted(kwargs.items()) ]) if args_string: formatted_args = args_string diff -r 8c8315bac6a8 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Sun Apr 20 09:45:00 2014 -0700 +++ b/Lib/unittest/test/testmock/testmock.py Tue Apr 22 08:58:02 2014 +0530 @@ -1206,6 +1206,12 @@ with self.assertRaises(AssertionError): m.hello.assert_not_called() + #Issue21256 + def test_sorted_call_signature(self): + m = Mock() + m.hello(name='hello', daddy='hero') + text = "call(daddy='hero', name='hello')" + self.assertEquals(repr(m.hello.call_args), text) def test_mock_add_spec(self): class _One(object): diff -r 8c8315bac6a8 Misc/NEWS --- a/Misc/NEWS Sun Apr 20 09:45:00 2014 -0700 +++ b/Misc/NEWS Tue Apr 22 08:58:02 2014 +0530 @@ -54,6 +54,9 @@ Library ------- +- Issue #21256: Call signature argument returns a sorted list. + This will help to write doc tests. + - Issue #15002: urllib.response object to use _TemporaryFileWrapper (and _TemporaryFileCloser) facility. Provides a better way to handle file descriptor close. Patch contributed by Christian Theune.