]> granicus.if.org Git - python/commitdiff
Closes Issue 21222.
authorKushal Das <kushaldas@gmail.com>
Tue, 15 Apr 2014 19:35:50 +0000 (01:05 +0530)
committerKushal Das <kushaldas@gmail.com>
Tue, 15 Apr 2014 19:35:50 +0000 (01:05 +0530)
Passing name keyword argument to mock.create_autospec now works.

Lib/unittest/mock.py
Lib/unittest/test/testmock/testmock.py
Misc/NEWS

index f1f65221d409807d86d7d8a0795344cf9e730f3c..13fd7b1af04ea92b25bbe4221fd6c15db52983f0 100644 (file)
@@ -2096,6 +2096,8 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None,
     elif is_type and instance and not _instance_callable(spec):
         Klass = NonCallableMagicMock
 
+    _name = _kwargs.pop('name', _name)
+
     _new_name = _name
     if _parent is None:
         # for a top level object no _new_name should be set
index 70f19d35732d73222b956babd5a4490158038c97..23675b9af6bee45f384993a59503a26378060415 100644 (file)
@@ -1182,6 +1182,10 @@ class MockTest(unittest.TestCase):
                 func.mock_calls, [call(1, 2), call(3, 4)]
             )
 
+    #Issue21222
+    def test_create_autospec_with_name(self):
+        m = mock.create_autospec(object(), name='sweet_func')
+        self.assertIn('sweet_func', repr(m))
 
     def test_mock_add_spec(self):
         class _One(object):
index 87553f0698ed13d4045e86ab6268be8454e3ac8c..04410743653aca6073461a2705dce99f69998b1e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #21222: Passing name keyword argument to mock.create_autospec now
+  works.
+
 - Issue #21197: Add lib64 -> lib symlink in venvs on 64-bit non-OS X POSIX.
 
 - Issue #17498: Some SMTP servers disconnect after certain errors, violating