I have written a test that tries to mock an exception as a side effect of a requests get operation. I am using the requests_mock
library as shown in the code listing below:
def test_owm_client_raises_error_for_timeout_error(owm_proxy: OWMProxy) -> None:
with requests_mock.Mocker() as m:
m.get(
"http://api.openweathermap.org/geo/1.0/direct/*",
exc=request_exceptions.Timeout,
)
city = "london"
utc_now = datetime.now(timezone.utc)
target_time = int((utc_now + timedelta(hours=10)).timestamp())
with pytest.raises(APIException):
owm_proxy.for_time(city, datetime.fromtimestamp(target_time).isoformat())
Is it possible to mock a url using wildcard parameters, e.g. http://api.openweathermap.org/geo/1.0/direct/*
? So far, the only way that I can simulate the desired effect of mocking a Timeout error is using requests.ANY
as the url parameter in the mock.