From 484f8a875b986690f9d8aec2089368b70184e009 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Wed, 16 Apr 2014 01:05:50 +0530 Subject: Closes Issue 21222. Passing name keyword argument to mock.create_autospec now works. --- Lib/unittest/mock.py | 2 ++ Lib/unittest/test/testmock/testmock.py | 4 ++++ Misc/NEWS | 3 +++ 3 files changed, 9 insertions(+) diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index f1f6522..13fd7b1 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -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 diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py index 70f19d3..23675b9 100644 --- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py @@ -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): diff --git a/Misc/NEWS b/Misc/NEWS index 87553f0..0441074 100644 --- 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 -- cgit v0.12