Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 484f8a8

Browse files
committed
Closes Issue 21222.
Passing name keyword argument to mock.create_autospec now works.
1 parent 9574355 commit 484f8a8

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/unittest/mock.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,8 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None,
20962096
elif is_type and instance and not _instance_callable(spec):
20972097
Klass = NonCallableMagicMock
20982098

2099+
_name = _kwargs.pop('name', _name)
2100+
20992101
_new_name = _name
21002102
if _parent is None:
21012103
# for a top level object no _new_name should be set

Lib/unittest/test/testmock/testmock.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,10 @@ def f(a, b):
11821182
func.mock_calls, [call(1, 2), call(3, 4)]
11831183
)
11841184

1185+
#Issue21222
1186+
def test_create_autospec_with_name(self):
1187+
m = mock.create_autospec(object(), name='sweet_func')
1188+
self.assertIn('sweet_func', repr(m))
11851189

11861190
def test_mock_add_spec(self):
11871191
class _One(object):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Core and Builtins
3737
Library
3838
-------
3939

40+
- Issue #21222: Passing name keyword argument to mock.create_autospec now
41+
works.
42+
4043
- Issue #21197: Add lib64 -> lib symlink in venvs on 64-bit non-OS X POSIX.
4144

4245
- Issue #17498: Some SMTP servers disconnect after certain errors, violating

0 commit comments

Comments
 (0)