Created
March 18, 2022 09:53
-
-
Save ilyasotkov/20207f7b83de84b5b19d22eac814e656 to your computer and use it in GitHub Desktop.
Pytest, cycling through responses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from itertools import cycle | |
from unittest import mock | |
def test_cycle_through_responses(monkeypatch): | |
return_data = ["h", "hello"] | |
test_mock = mock.Mock(side_effect=cycle(return_data)) | |
m = sys.modules[__name__] | |
monkeypatch.setattr(m, "myfunc", test_mock) | |
assert myfunc() == "h" | |
assert myfunc() == "hello" | |
assert myfunc() == "h" | |
assert myfunc() == "hello" | |
def myfunc(): | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment