pip install httpretty
python
import httpretty
import requests
httpretty.enable()
httpretty.register_uri(httpretty.GET, "http://example.com/api", body="Hello, World!")
response = requests.get("http://example.com/api")
print(response.text)
httpretty.disable()