Created
January 7, 2026 18:42
-
-
Save jangia/dfbafcc72df4fa2492716abbc71b37d8 to your computer and use it in GitHub Desktop.
Mock HTTP Calls Effortlessly in Python with responses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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