Commit 26581e31 authored by Kushal Das's avatar Kushal Das

Closes Issue 21222.

Passing name keyword argument to mock.create_autospec now works.
parent 916ff51e
...@@ -2096,6 +2096,8 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None, ...@@ -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): elif is_type and instance and not _instance_callable(spec):
Klass = NonCallableMagicMock Klass = NonCallableMagicMock
_name = _kwargs.pop('name', _name)
_new_name = _name _new_name = _name
if _parent is None: if _parent is None:
# for a top level object no _new_name should be set # for a top level object no _new_name should be set
......
...@@ -1182,6 +1182,10 @@ class MockTest(unittest.TestCase): ...@@ -1182,6 +1182,10 @@ class MockTest(unittest.TestCase):
func.mock_calls, [call(1, 2), call(3, 4)] 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): def test_mock_add_spec(self):
class _One(object): class _One(object):
......
...@@ -37,6 +37,9 @@ Core and Builtins ...@@ -37,6 +37,9 @@ Core and Builtins
Library 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 #21197: Add lib64 -> lib symlink in venvs on 64-bit non-OS X POSIX.
- Issue #17498: Some SMTP servers disconnect after certain errors, violating - Issue #17498: Some SMTP servers disconnect after certain errors, violating
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment