[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

Issue 21222: Mock create_autospec with name argument fails

classification
Title: Mock create_autospec with name argument fails
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: kushal.das, michael.foord, python-dev, steve.dower
Priority: normal Keywords: patch

Created on 2014-04-14 19:54 by kushal.das, last changed 2020-07-03 22:34 by steve.dower. This issue is now closed.

Files
File name Uploaded Description Edit
issue21222.patch kushal.das, 2014-04-14 22:00 review
issue21222_v2.patch kushal.das, 2014-04-15 17:32 New patchset with changes made as suggested. review
Pull Requests
URL Status Linked Edit
PR 21304 open steve.dower, 2020-07-03 22:33
Messages (7)
msg216190 - (view) Author: Kushal Das (kushal.das) * Date: 2014-04-14 19:54
>>> from unittest import mock
>>> def b():
...   print("hello")
... 
>>> q = mock.create_autospec(b, name="a")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kdas/code/python/cpython3/Lib/unittest/mock.py", line 2092, in create_autospec
    name=_name, **_kwargs)
TypeError: type object got multiple values for keyword argument 'name'

The issue was originally reported on mock bug tracker. I am working on a patch for the same.
msg216230 - (view) Author: Kushal Das (kushal.das) * Date: 2014-04-14 22:00
Fix for the issue with test case. We are checking name in keyword arguments, if found replace _name with it and delete it from keyword arguments.
msg216311 - (view) Author: Michael Foord (michael.foord) * Date: 2014-04-15 15:37
You can use kwargs.pop instead of the two step fetch and delete. 

For the test, could you add an assert that the name is used. Can you add an extra underscore to the method name, to make it: test_create_autospec_with_name
msg216343 - (view) Author: Kushal Das (kushal.das) * Date: 2014-04-15 17:32
New patchset with changes made as suggested.
msg216367 - (view) Author: Michael Foord (michael.foord) * Date: 2014-04-15 19:28
Looks good to me, but please change qobj and add a NEWS entry.
msg216371 - (view) Author: Roundup Robot (python-dev) Date: 2014-04-15 19:53
New changeset d471b0d38516 by Kushal Das in branch '3.4':
Closes Issue 21222.
http://hg.python.org/cpython/rev/d471b0d38516
msg372968 - (view) Author: Steve Dower (steve.dower) * Date: 2020-07-03 22:34
New changeset 941117aaa32bf8b02c739ad848ac727292f75b05 by Steve Dower in branch '3.9':
bpo-21222: Fix improperly merged change so that final hooks are called before types are cleared (GH-21304)
https://github.com/python/cpython/commit/941117aaa32bf8b02c739ad848ac727292f75b05
History
Date User Action Args
2020-07-03 22:34:53steve.dowersetmessages: + msg372968
2020-07-03 22:33:21steve.dowersetnosy: + steve.dower

pull_requests: + pull_request20455

2020-07-03 22:32:54steve.dowersetnosy: - steve.dower
2020-07-03 22:32:47steve.dowersetpull_requests: - pull_request20453
2020-07-03 22:06:09steve.dowersetnosy: + steve.dower

pull_requests: + pull_request20453

2014-04-15 19:53:09python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg216371

resolution: fixed
stage: resolved

2014-04-15 19:28:42michael.foordsetmessages: + msg216367
2014-04-15 17:32:17kushal.dassetfiles: + issue21222_v2.patch

messages: + msg216343

2014-04-15 15:37:44michael.foordsetnosy: + michael.foord
messages: + msg216311
2014-04-14 22:00:43kushal.dassetfiles: + issue21222.patch
keywords: + patch
messages: + msg216230
2014-04-14 19:54:11kushal.dascreate