Open GoogleCodeExporter opened 8 years ago
You can use side_effect to achieve what you want. For example:
returns = {}
def side_effect(*args, **kwargs):
key = (args, tuple(kwargs.items()))
return returns.setdefault(key, MagicMock())
Enclose it in a factory function if you want to reuse it with several mocks. It
relies on hashable args - but can be modified if you need that. Fixing it in a
general way for non-hashable argument sets without *killing* performance is
"non-trivial".
Original comment by fuzzyman
on 28 Mar 2012 at 12:57
Original issue reported on code.google.com by
k...@k-bx.com
on 28 Mar 2012 at 12:12