pytest-httpx2
A pytest plugin for mocking out httpx2 using respx.
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low friction install with a single runtime dependency (respx).
- The package is actively maintained with recent releases and a non-archived repository.
License · maintenance · safety
BSD-3-Clause (permissive) — BSD-3-Clause is permissive; you can use this in commercial and private projects with minimal restrictions.
last release 2026-05-20 (86 days) · last repo commit 2026-05-22 · 19 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 140,866 downloads/mo, #11,261 on PyPI
Alternatives
Verify before relying
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- 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.
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 on it.
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
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.
Requires Python 3.10 or later.
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
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 packagerespx |
| 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 |
| Classifiers | Operating System :: OS IndependentProgramming Language :: Python :: 3 |
Evidence: pytest_httpx2-1.0.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pytest httpx2 mocking”
- pytest-httpx2A pytest plugin that mocks httpx2 HTTP requests using respx, letting…
- pytest-responsesAutomatically mocks HTTP requests across your pytest test suite using…
- pytest-mockProvides a pytest fixture that wraps the mock library's patching API,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also pytest_httpserver · respx · pytest-responses · urllib3-mock · httpx2 · aioresponses · pytest-mock · aresponses · pytest-localserver · pytest-console-scripts