changeset: 91102:8e05e15901a8 user: Kushal Das date: Mon Jun 09 13:45:56 2014 +0530 files: Lib/unittest/mock.py Lib/unittest/test/testmock/testmock.py Misc/NEWS description: Closes #21256: Printout of keyword args in deterministic order in mock calls. Printout of keyword args should be in deterministic order in a mock function call. This will help to write better doctests. diff -r d6ac4b6020b9 -r 8e05e15901a8 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Mon Jun 09 09:15:42 2014 +0300 +++ b/Lib/unittest/mock.py Mon Jun 09 13:45:56 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 d6ac4b6020b9 -r 8e05e15901a8 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Mon Jun 09 09:15:42 2014 +0300 +++ b/Lib/unittest/test/testmock/testmock.py Mon Jun 09 13:45:56 2014 +0530 @@ -1206,6 +1206,12 @@ with self.assertRaises(AssertionError): m.hello.assert_not_called() + #Issue21256 printout of keyword args should be in deterministic order + 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 d6ac4b6020b9 -r 8e05e15901a8 Misc/NEWS --- a/Misc/NEWS Mon Jun 09 09:15:42 2014 +0300 +++ b/Misc/NEWS Mon Jun 09 13:45:56 2014 +0530 @@ -92,6 +92,9 @@ Library ------- +- Issue #21256: Printout of keyword args should be in deterministic order in + a mock function call. This will help to write better doctests. + - Issue #21677: Fixed chaining nonnormalized exceptions in io close() methods. - Issue #11709: Fix the pydoc.help function to not fail when sys.stdin is not a