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