A utility for mocking out the Python HTTPX and HTTP Core libraries.
Project description
RESPX - Mock HTTPX with awesome request patterns and response side effects.
Documentation
Full documentation is available at lundberg.github.io/respx
QuickStart
RESPX is a simple, yet powerful, utility for mocking out the HTTPX, and HTTP Core, libraries.
Start by patching HTTPX
, using
respx.mock
, then add request
routes to mock
responses.
import httpx
import respx
from httpx import Response
@respx.mock
def test_example():
my_route = respx.get("https://example.org/").mock(return_value=Response(204))
response = httpx.get("https://example.org/")
assert my_route.called
assert response.status_code == 204
Read the User Guide for a complete walk-through.
pytest + httpx
For a neater pytest
experience, RESPX includes a respx_mock
fixture for easy
HTTPX
mocking, along with an optional respx
marker to fine-tune the mock
settings.
import httpx
import pytest
def test_default(respx_mock):
respx_mock.get("https://foo.bar/").mock(return_value=httpx.Response(204))
response = httpx.get("https://foo.bar/")
assert response.status_code == 204
@pytest.mark.respx(base_url="https://foo.bar")
def test_with_marker(respx_mock):
respx_mock.get("/baz/").mock(return_value=httpx.Response(204))
response = httpx.get("https://foo.bar/baz/")
assert response.status_code == 204
Installation
Install with pip:
$ pip install respx
Requires Python 3.7+ and HTTPX 0.21+. See Changelog for older HTTPX compatibility.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file respx-0.21.1.tar.gz
.
File metadata
- Download URL: respx-0.21.1.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bd7fe21bfaa52106caa1223ce61224cf30786985f17c63c5d71eff0307ee8af |
|
MD5 | 66755852123f39634eee126f18cd4c27 |
|
BLAKE2b-256 | fd72979e475ade69bcbb18288604aacbdc77b44b3bd1133e2c16660282a9f4b8 |
File details
Details for the file respx-0.21.1-py2.py3-none-any.whl
.
File metadata
- Download URL: respx-0.21.1-py2.py3-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05f45de23f0c785862a2c92a3e173916e8ca88e4caad715dd5f68584d6053c20 |
|
MD5 | 6f0313019b23d3e5d98690ab35e33726 |
|
BLAKE2b-256 | a55c428523509b26c243c1e93aa2ae385def597ef1fbdbbd47978430ba19037d |