diff -r 2d33cbf02522 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Tue Apr 15 14:24:53 2014 +0100 +++ b/Lib/unittest/mock.py Tue Apr 15 23:01:08 2014 +0530 @@ -2103,6 +2103,8 @@ 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 -r 2d33cbf02522 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Tue Apr 15 14:24:53 2014 +0100 +++ b/Lib/unittest/test/testmock/testmock.py Tue Apr 15 23:01:08 2014 +0530 @@ -1182,6 +1182,10 @@ func.mock_calls, [call(1, 2), call(3, 4)] ) + #Issue21222 + def test_create_autospec_with_name(self): + qobj = mock.create_autospec(object(), name='sweet_func') + self.assertIn('sweet_func', repr(qobj)) def test_mock_add_spec(self): class _One(object):