mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Closes Issue 21222.
Passing name keyword argument to mock.create_autospec now works.
This commit is contained in:
parent
9574355ff3
commit
484f8a875b
3 changed files with 9 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue