--- id: pytest-httpserver version: "1.1.5" license: unclear license_treatment: unclear maintenance: active --- # pytest_httpserver — pytest-httpserver is a httpserver for pytest License: unclear · Maintenance: active · Downloads: 3.9M/mo ## 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 above — 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 pip install pytest-httpserver uv add pytest-httpserver poetry add pytest-httpserver ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 3.9M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags mock http server pytest, fake http server testing, http client test fixture, localhost test server, http request response mocking, http-mocking, test-fixture [View on SkillFed](https://skillfed.io/packages/pytest-httpserver) · [View on PyPI](https://pypi.org/project/pytest-httpserver/)