Skip to main content

A utility for mocking out the Python HTTPX and HTTP Core libraries.

Project description

RESPX

RESPX - Mock HTTPX with awesome request patterns and response side effects.


tests codecov PyPi Version Python Versions

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.6+ and HTTPX 0.18+. See Changelog for older HTTPX compatibility.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

respx-0.18.0b0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

respx-0.18.0b0-py2.py3-none-any.whl (29.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file respx-0.18.0b0.tar.gz.

File metadata

  • Download URL: respx-0.18.0b0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for respx-0.18.0b0.tar.gz
Algorithm Hash digest
SHA256 af8b88f19eece5e81dbfcb7212cf52d4dedf495169c3e99800f18d5532aec4a8
MD5 f84a86381d0b3c11f04f9cc99500d17e
BLAKE2b-256 7dab3ec8713c3524ec96f65ce9ce647c26d2f735ae8816c2a70327e417358f34

See more details on using hashes here.

File details

Details for the file respx-0.18.0b0-py2.py3-none-any.whl.

File metadata

  • Download URL: respx-0.18.0b0-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for respx-0.18.0b0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 85b438e9f5173426a89b89ff795ae2e0d8dfd120e4c1dcd4729307efd796dceb
MD5 3676d253933252df8941158ca34744a2
BLAKE2b-256 f0024b2f8938cc75658109b92019ea96f5bff10245e74aa4133f423b230ce5fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page