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
Priority: normal Keywords: patch

Created on 2014-04-14 19:54 by kushal.das, last changed 2014-04-15 19:53 by python-dev. 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
Messages (6)
msg216190 - (view) Author: Kushal Das (kushal.das) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2014-04-15 17:32
New patchset with changes made as suggested.
msg216367 - (view) Author: Michael Foord (michael.foord) * (Python committer) 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
History
Date User Action Args
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