pytest monkeypatch: it is possible to return different values each time when patched method called?
<p>In <code>unittest</code> I can assert to <a href="https://docs.python.org/3.5/library/unittest.mock.html?highlight=side_effect#unittest.mock.Mock.side_effect" rel="nofollow">side_effect</a> iterable with values - each of them one-by-one will be returned when patched method called, moreover I <a href="http://stackoverflow.com/a/7665754/1879101">found</a> that in <code>unittest</code> my patched method can return different results according to input arguments. Can I make something like that in pytest? <a href="http://doc.pytest.org/en/latest/monkeypatch.html#example-preventing-requests-from-remote-operations" rel="nofollow">Documentation</a> does not mention this.</p>

<p>You could certainly monkeypatch something with a class with a <code>__call__</code> attribute which does whatever you want - however, nothing keeps you from using <code>unittest.mock</code> with pytest - there's even the <a href="https://github.com/pytest-dev/pytest-mock/" rel="nofollow"><code>pytest-mock</code> plugin</a> to make this easier.</p>

python unit-testing py.test python-unittest