mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
[3.13] gh-120732: Fix name
passing to Mock
, when using kwargs to create_autospec
(GH-120737) (#120760)
gh-120732: Fix `name` passing to `Mock`, when using kwargs to `create_autospec` (GH-120737)
(cherry picked from commit 1e4815692f
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
d3918eb89a
commit
355d928e55
3 changed files with 13 additions and 7 deletions
|
@ -2755,6 +2755,12 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None,
|
|||
if not unsafe:
|
||||
_check_spec_arg_typos(kwargs)
|
||||
|
||||
_name = kwargs.pop('name', _name)
|
||||
_new_name = _name
|
||||
if _parent is None:
|
||||
# for a top level object no _new_name should be set
|
||||
_new_name = ''
|
||||
|
||||
_kwargs.update(kwargs)
|
||||
|
||||
Klass = MagicMock
|
||||
|
@ -2772,13 +2778,6 @@ 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
|
||||
_new_name = ''
|
||||
|
||||
mock = Klass(parent=_parent, _new_parent=_parent, _new_name=_new_name,
|
||||
name=_name, **_kwargs)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue