Mock HTTPX with awesome request patterns and response side effects.
import httpx import respx from httpx import Response @respx.mock def test_example(): my_route = respx.get("https://foo.bar/").mock(return_value=Response(204)) response = httpx.get("https://foo.bar/") assert my_route.called assert response.status_code == 204
Read the User Guide for a complete walk-through.
As of RESPX version
0.15.0, the API has changed, but kept with deprecation warnings, later to be broken for backward compatibility in
0.16.0. Read the Upgrade Guide for an easier transision to latest release.
Install with pip:
$ pip install respx
Requires Python 3.6+ and HTTPX 0.15+. See Changelog for older HTTPX compatibility.