--- id: pytest-httpx2 version: "1.0.0" license: BSD-3-Clause license_treatment: permissive maintenance: active --- # pytest-httpx2 — A pytest plugin for mocking out httpx2 using respx. License: permissive · Maintenance: active · Downloads: 140.9K/mo ## 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 above — 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 pip install pytest-httpx2 uv add pytest-httpx2 poetry add pytest-httpx2 ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 140.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest httpx2 mocking, mock http requests in tests, respx pytest plugin, httpx2 test fixtures, fake http responses pytest, http-mocking, test-fixtures [View on SkillFed](https://skillfed.io/packages/pytest-httpx2) · [View on PyPI](https://pypi.org/project/pytest-httpx2/)