python - Remove call() when using Mock -
in python 2.6 or 2.7, want rid of 'call' stuff when using mock.call_args_list.
i want check if mock called when argument.
i have like:
a = mock() ... self.assertequal(a.call_args_list, ...)
but call_args_list looks like:
[call(arg1, arg2, arg3), call(...)]
how can access arg2 value precisely without recreating complete call object?
if there way iterate in "call" object , list of argument , extract whatever need?
the thing had no problem, call_args_list returned me lists without "call" stuff , able wanted do, reason "call" started appearing , don't know how handle correctly.
you can do:
>>> import mock >>> my_call = mock.call('test', example=3) >>> name, args, kwargs = my_call >>> name '' >>> args ('test',) >>> kwargs {'example': 3}
this give name (not available), positional arguments , keyword arguments of call. according the documentation, call()
objects in call_args_list
tuples 2 values, not three. can do:
>>> args, kwargs = my_call
you can use indexing values. example, my_call[2]
give keyword arguments. can used convert call_args_list
arguments:
>>> call1 = mock.call('test', example=3) >>> call2 = mock.call('test', example=4, value=5) >>> call_args_list = [call1, call2] >>> [(item[1], item[2]) item in call_args_list] [(('test',), {'example': 3}), (('test',), {'example': 4, 'value': 5})]
Comments
Post a Comment