Skip to content

Instantly share code, notes, and snippets.

@jangia
Created January 7, 2026 18:42
Show Gist options
  • Select an option

  • Save jangia/dfbafcc72df4fa2492716abbc71b37d8 to your computer and use it in GitHub Desktop.

Select an option

Save jangia/dfbafcc72df4fa2492716abbc71b37d8 to your computer and use it in GitHub Desktop.
Mock HTTP Calls Effortlessly in Python with responses
import responses
import requests
@responses.activate
def test_not_found():
responses.add(
responses.GET,
"https://api.example.com/user/42",
json={"error": "not found"},
status=404
)
resp = requests.get("https://api.example.com/user/42")
assert resp.status_code == 404
assert resp.json()["error"] == "not found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment