skillfed

pytest-httpx2

A pytest plugin for mocking out httpx2 using respx.

pytest-httpx2 v1.0.0 140.9K downloads/30d#11,261 on PyPI19
Permissive license BSD-3-Clause Active released

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

uv

uv add pytest-httpx2

poetry

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

Operating System :: OS IndependentProgramming Language :: Python :: 3

Tags

pytest httpx2 mockingmock http requests in testsrespx pytest pluginhttpx2 test fixturesfake http responses pytest
http-mockingtest-fixtures

More Testing packages