]> granicus.if.org Git - python/commitdiff
bpo-37212: Preserve keyword argument order in unittest.mock.call and error messages...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 9 Sep 2019 11:42:43 +0000 (04:42 -0700)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2019 11:42:43 +0000 (04:42 -0700)
(cherry picked from commit 9d607061c9c888913ae2c18543775cf360d55f27)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
Lib/unittest/mock.py
Lib/unittest/test/testmock/testmock.py
Misc/NEWS.d/next/Library/2019-06-22-22-00-35.bpo-37212.Zhv-tq.rst [new file with mode: 0644]

index 4c76f53f3870c09c2b28986a22fb5a9e8b8e48fe..7a4fcf4e3aa97f5878872cf1c9d75044dbc57800 100644 (file)
@@ -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
index d3a1e89da81a1ea4dbad122c5c062ed92a06817a..413ee6895101937d0611721432170a27cf2ec2ed 100644 (file)
@@ -1563,11 +1563,11 @@ class MockTest(unittest.TestCase):
             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
diff --git a/Misc/NEWS.d/next/Library/2019-06-22-22-00-35.bpo-37212.Zhv-tq.rst b/Misc/NEWS.d/next/Library/2019-06-22-22-00-35.bpo-37212.Zhv-tq.rst
new file mode 100644 (file)
index 0000000..520a022
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`unittest.mock.call` now preserves the order of keyword arguments in
+repr output. Patch by Karthikeyan Singaravelan.