pytest-httpx2
A pytest plugin for mocking out httpx2 using respx.
What it is and what it does
pytest-httpx2 is a pytest plugin that intercepts httpx2 HTTP calls during tests and replaces them with mocked responses defined via respx. Instead of your tests making real network requests, you register expected request patterns and specify what response each should return; the plugin then routes matching calls to those mocks. It integrates directly into pytest's fixture system, injecting a respx.Router as the httpx2_mock fixture that you use to set up your mock responses.
The plugin supports both inline fixture configuration (passing the router directly to your test function) and pytest marker-based configuration via @pytest.mark.httpx2, which lets you set a base URL and other options declaratively. It has a single runtime dependency on respx and requires Python 3.10 or later.
Use it for:
- Unit test an API client that uses httpx2 without making real network calls or hitting external services.
- Test error handling by mocking specific HTTP status codes and response bodies from an API.
- Verify that your code constructs the correct request (method, URL, headers, body) before sending it.
- Run tests in CI/CD environments where network access is restricted or unreliable.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that mocks httpx2 HTTP requests using respx, letting you define expected requests and responses in tests without hitting real endpoints.
Yes, if you use httpx2 in your project and need to test code that makes HTTP calls. The plugin is lightweight, actively maintained, has no known vulnerabilities, and integrates cleanly into pytest's fixture model. Install it alongside your test dependencies.
Install
pytest-httpx2 on PyPI
pip
pip install pytest-httpx2uv
uv add pytest-httpx2poetry
poetry add pytest-httpx2Installing pytest-httpx2
Before you install
Low friction install with a single runtime dependency (respx). The package is actively maintained with recent releases and a non-archived repository.
License in practice
BSD-3-Clause is permissive; you can use this in commercial and private projects with minimal restrictions.
Quickstart
pip install pytest-httpx2
import httpx2
def test_example(httpx2_mock):
httpx2_mock.post("https://example.com/api").respond(201)
response = httpx2.post("https://example.com/api")
assert response.status_code == 201
Requires Python 3.10 or later.
Verify before relying
- Whether httpx2 is a stable, widely-used HTTP client or a newer/experimental library.
- How respx's mocking approach compares to other httpx mocking strategies in the ecosystem.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — respx |
| Maintenance | actively maintained — 86 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 140,866/month — #11,261 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_httpx2-1.0.0-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest_httpserverA pytest fixture and standalone context manager…
unclear · top 5,000 on PyPI
respxRESPX mocks HTTPX and HTTP Core libraries for…
permissive · top 1,000 on PyPI
pytest-responsesAutomatically mocks HTTP requests across your…
permissive · top 15,000 on PyPI
urllib3-mockMocks urllib3 HTTP requests in tests by…
permissive · top 15,000 on PyPI
httpx2HTTPX2 is a fully featured HTTP client library…
permissive · top 1,000 on PyPI
aioresponsesMocks HTTP requests made by aiohttp's…
permissive · top 5,000 on PyPI
pytest-mockProvides a pytest fixture that wraps the mock…
permissive · top 1,000 on PyPI
aresponsesMocks external HTTP/HTTPS services for…
permissive · top 15,000 on PyPI
pytest-localserverProvides pytest fixtures that spin up local…
permissive · top 15,000 on PyPI
pytest-console-scriptsA pytest plugin that runs Python console…
permissive · top 15,000 on PyPI