Skip to main content

pytest fixture for HTTPX

Project description

pytest fixture for HTTPX

pypi version Build status Coverage Code style: black Number of tests Number of downloads

Notice: This module is still under development, versions prior to 1.0.0 are subject to breaking changes without notice.

Use pytest_httpx.httpx_mock pytest fixture to mock httpx requests.

Add responses

import httpx
from pytest_httpx import httpx_mock, HTTPXMock


def test_something(httpx_mock: HTTPXMock):
    httpx_mock.add_response("http://test_url")

    response = httpx.get("http://test_url")

In case more than one request is sent to the same URL, the responses will be sent in the registration order.

First response will be sent as response of the first request and so on.

If the number of responses is lower than the number of requests on an URL, the last response will be used to reply to all subsequent requests on this URL.

If all responses are not sent back during test execution, the test case will fail at teardown.

Check sent requests

import httpx
from pytest_httpx import httpx_mock, HTTPXMock


def test_something(httpx_mock: HTTPXMock):
    httpx_mock.add_response("http://test_url")

    response = httpx.get("http://test_url")

    request = httpx_mock.get_request("http://test_url")

A request can only be retrieved once per test case.

Calling order is preserved, so in case more than one request is sent to the same URL, the first one will be returned first.

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

pytest_httpx-0.0.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

pytest_httpx-0.0.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_httpx-0.0.2.tar.gz.

File metadata

  • Download URL: pytest_httpx-0.0.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.7

File hashes

Hashes for pytest_httpx-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e7156769d1476c38ea35dfed687874a508928e8bc56cbd848fa6d62d29d5e02b
MD5 0cde2477472ac33f723c7d7e96e63460
BLAKE2b-256 c9fb133f80f54d67874fb603deb62d911a37f9d279b0bce9bef3b4e3fbcd3765

See more details on using hashes here.

File details

Details for the file pytest_httpx-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pytest_httpx-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.1

File hashes

Hashes for pytest_httpx-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf192c2484a2220af2a69dfdffe7a4221d8037b6e2d102467912b0488e237819
MD5 83487f2b5df1e87980fd1cdc64009698
BLAKE2b-256 1484881cebfbc24529f33e50f989bef623c2c8355604a1a67bb792a5a6b6f17c

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