summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-19 20:59:28 (GMT)
committerGitHub <noreply@github.com>2024-06-19 20:59:28 (GMT)
commit355d928e55d7c82f91989d08653215cb7e151c6e (patch)
tree51647c7a03b15c6e8977027476b2e4ce4a361c5a /Lib/unittest
parentd3918eb89a2bfb9165a9ec27806436a7ebe49276 (diff)
downloadcpython-355d928e55d7c82f91989d08653215cb7e151c6e.zip
cpython-355d928e55d7c82f91989d08653215cb7e151c6e.tar.gz
cpython-355d928e55d7c82f91989d08653215cb7e151c6e.tar.bz2
[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 1e4815692f6c8a37a3974d0d7d2025494d026d76) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index b701ec3..f7ab4a5 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -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)