python - Creating an autospec'd mock with a name value -


i'm trying use mock.create_autospec create autospecc'd mock name kwarg. however, typeerror exception whenever set name kwarg.

here's example:

>>> import mock >>> def a(): ...  print "blah" ...  >>> a() blah >>> q = mock.create_autospec(a) >>> q <function @ 0x7f184ceb1938> >>> q() <magicmock name='mock()' id='139742347069904'> 

mock() isn't descriptive name magicmock object, try set value name:

>>> q = mock.create_autospec(a, name="a") traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "/usr/lib/python2.7/site-packages/mock.py", line 2186, in create_autospec     name=_name, **_kwargs) typeerror: type object got multiple values keyword argument 'name' 

why happen? when try make regular magicmock, things go fine:

>>> q = mock.magicmock(name="a") >>> q <magicmock name='a' id='139742346475088'> 

it looks conflict of provided , generated names. it's bug, should try reporting it.

there way create autospec'd mock meaningful name, requires patching:

with mock.patch('__main__.a', autospec=true):     print(repr(a()))  # <magicmock name='a()' id='140705539482000'> 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -