我正在尝试模拟extra_get()
方法的调用,该方法通常返回一个字典列表。据我对Mock的理解,如果我想返回docs,我应该设置side_effect参数。
client.extra_get = mock.Mock(
**{'side_effect': [{'foo': 'bar'}]})
但是下面的代码调用了这个模拟的方法:
extra = client.extra_get(request, type_id)
result = {x.key: x.value for x in extra}
return result
解释失败,因为这里没有列表,而是dict {'foo': 'bar'}
。我哪里做错了?如何让Mock方法返回一个字典列表?
发布于 2016-09-17 01:47:41
with mock.patch.object(client, 'extra_get', return_value=[{...}, {...}]) as mock_get:
# fill in the rest
https://stackoverflow.com/questions/39507864
复制相似问题