HTTPretty
HTTP request interceptor library for Python testing. HTTPretty patches Python's socket library to intercept all HTTP connections — it doesn't require changing how HTTP clients are created. Supports all major Python HTTP libraries (requests, httpx, urllib3, boto3, aiohttp) and allows registering fake responses for specific URLs. Used for unit testing code that makes HTTP requests without mocking individual client instances.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Local testing library — no network calls when properly configured. Socket-level patching prevents accidental real API calls in tests.
⚡ Reliability
Best When
You need to mock HTTP requests in Python agent tests across multiple HTTP libraries without modifying client creation code — HTTPretty's socket-level interception works universally.
Avoid When
You're using async HTTP (httpx async, aiohttp) — use respx or aioresponses instead. Or if you need detailed request inspection — use responses library.
Use Cases
- • Mock external HTTP API calls in Python agent unit tests without changing how agent code creates HTTP clients
- • Test agent code that uses multiple HTTP libraries (requests + boto3) in the same test — HTTPretty intercepts at socket level
- • Simulate API error responses (429, 500, timeouts) for agent error handling tests without spinning up mock servers
- • Test agent retry logic by registering sequences of responses for the same URL — first call returns 429, second returns 200
- • Write tests for agent code that reads from web APIs without network access in CI environments
Not For
- • Async tests with httpx or aiohttp — HTTPretty has limited async support; use respx for httpx or aioresponses for aiohttp
- • Tests needing response inspection (what request was sent) — use responses or respx which provide better request capture
- • Applications using raw socket connections — HTTPretty patches socket, but very low-level socket code may bypass it
Interface
Authentication
Local testing library — no external auth or network calls during test.
Pricing
MIT-licensed open source Python package.
Agent Metadata
Known Gotchas
- ⚠ HTTPretty must be activated before any HTTP call — use @httpretty.activate decorator or httpretty.enable() context manager; registering mocks before activation has no effect
- ⚠ allow_net_connect=False must be set to prevent real network calls — without it, unmatched requests hit real servers in tests causing flaky results and unintended side effects
- ⚠ HTTPretty has known issues with parallel test execution (pytest-xdist) — socket-level patching is process-global; use separate processes (not threads) for parallel HTTPretty tests
- ⚠ Async HTTP clients (httpx async, aiohttp) are not fully supported — HTTPretty intercepts at synchronous socket level; use respx for httpx and aioresponses for aiohttp
- ⚠ Response streaming with large bodies may behave differently — HTTPretty buffers responses in memory; streaming agent code may not behave the same as with real streaming responses
- ⚠ pytest-httpretty plugin may conflict with direct HTTPretty usage — choose one approach per test suite to avoid double-patching
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for HTTPretty.
Scores are editorial opinions as of 2026-03-06.