pytest_httpserver
pytest-httpserver is a httpserver for pytest
What it is and what it does
pytest-httpserver provides a pytest fixture and standalone context manager that starts a local HTTP server to intercept and respond to client requests during tests. Instead of mocking individual HTTP calls, you define expectations—matching on URI, method, headers, query strings, and request body—and specify what response the server should send back. The server can handle permanent expectations (served repeatedly), one-shot expectations (served once), and ordered expectations (served in strict sequence). Responses can be raw data, JSON, Werkzeug Response objects, or custom functions.
The package is built on Werkzeug for HTTP parsing and request/response handling. It works both as a pytest fixture (automatically started and stopped around each test) and as a standalone context manager for non-pytest code. This approach lets you test HTTP clients in isolation without external network calls, making tests faster and more reliable.
Use it for:
- Test an HTTP client library by mocking server responses without running a real server.
- Verify that your code sends the correct HTTP method, headers, and body to an API.
- Test ordered sequences of requests in a single test, ensuring your client makes calls in the right order.
- Run integration tests in CI/CD pipelines where external HTTP services may be unavailable.
- Use the standalone context manager in non-pytest code to set up temporary HTTP server expectations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest fixture and standalone context manager that runs a fake HTTP server on localhost, letting you test HTTP clients without hitting real servers by defining expected requests and their responses.
Yes, if you need to test HTTP clients. The package is actively maintained, has low install friction, and fills a clear testing gap. The only caveat is the unclear license status—verify the actual license before use in proprietary projects. For open-source work or internal testing, it is a solid choice.
Install
pytest-httpserver on PyPI
pip
pip install pytest-httpserveruv
uv add pytest-httpserverpoetry
poetry add pytest-httpserverInstalling pytest_httpserver
Before you install
Low friction install with a single runtime dependency (Werkzeug). Actively maintained with recent commits and steady releases since 2018.
License in practice
License status is unclear—no SPDX identifier or raw license text is declared in the package metadata, so you should verify the actual license terms before use in proprietary or restricted contexts.
Quickstart
pip install pytest-httpserver
import pytest
from pytest_httpserver import HTTPServer
def test_client(httpserver):
httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"})
# Your HTTP client code here
assert requests.get(httpserver.url_for("/foobar")).json() == {"foo": "bar"}
Requires Python 3.10 or later.
Verify before relying
- Whether the package is licensed under an open-source or proprietary license (license metadata is missing).
- Whether error responses and edge cases can be simulated (not explicitly stated in the fact sheet).
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — Werkzeug |
| Maintenance | actively maintained — 181 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,898,973/month — #2,457 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_httpserver-1.1.5-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
pytest-httpx2A pytest plugin that mocks httpx2 HTTP requests…
permissive · top 15,000 on PyPI
pytest-localserverProvides pytest fixtures that spin up local…
permissive · top 15,000 on PyPI
pytest-responsesAutomatically mocks HTTP requests across your…
permissive · top 15,000 on PyPI
pytest-httpbinProvides a pytest fixture that runs a local…
permissive · top 15,000 on PyPI
responsesMocks HTTP requests made by the requests…
permissive · top 1,000 on PyPI
urllib3-mockMocks urllib3 HTTP requests in tests by…
permissive · top 15,000 on PyPI
aiointerceptIntercepts aiohttp client requests by routing…
permissive · top 15,000 on PyPI
pytest-subprocessPytest plugin that intercepts and fakes…
permissive · top 15,000 on PyPI
mocketMocket is a socket mocking framework that…
permissive · top 15,000 on PyPI
httmockIntercepts and mocks HTTP requests made by the…
permissive · top 5,000 on PyPI