I am trying to test code that depends on a third party and would like to use monkeypatch to replicate what I expect a request will return. Here is a minimal example of the code that I have.
import requests
def get_urls(*urls):
results = []
for url in urls:
results.append(requests.get(url).text)
For my tests, I have something like the following:
from my_package import get_urls
def test_get_urls():
urls = ("https://example.com/a", "https://example.com/b", "https://example.com/c")
assert len(get_urls(urls)) == 3
How can I monkeypatch each of the calls to requests.get using monkeypatch.setattr? The mock package seems to be able to do this using side effects. How do I do this with pytest?