skillfed

pytest_httpserver

pytest-httpserver is a httpserver for pytest

pytest-httpserver v1.1.5 3.9M downloads/30d#2,457 on PyPI253
License unclear Active released

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-httpserver

uv

uv add pytest-httpserver

poetry

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 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

Development Status :: 3 - AlphaFramework :: PytestIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Libraries :: Python Modules

Tags

mock http server pytestfake http server testinghttp client test fixturelocalhost test serverhttp request response mocking
http-mockingtest-fixture

More Python Modules packages