A pytest plugin for mocking out HTTPX2 using RESPX.
Install with pip, or your favourite package manager:
pip install pytest-httpx2Enable the pytest plugin and mock fixture, e.g. in your pyproject.toml:
[tool.pytest]
addopts = ["-p pytest_httpx2"]import httpx2
def test_foobar(httpx2_mock: respx.Router) -> None:
httpx2_mock.post("https://example.com/foobar").respond(201)
response = httpx2.post("https://example.com/foobar")
assert response.status_code == 201Configure the httpx2_mock fixture with the included marker:
import pytest
import httpx2
@pytest.mark.httpx2(base_url="https://example.com")
def test_hamspam(httpx2_mock: respx.Router) -> None:
httpx2_mock.get("/hamspam").respond(json={"id": 1337})
response = httpx2.get("https://example.com/hamspam")
assert response.status_code == 200
assert response.json() == {"id": 1337}See respx documentation for more
configuration options and api.