pytest fixture for HTTPX
Project description
pytest fixture for HTTPX
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
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
Hashes for pytest_httpx-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf192c2484a2220af2a69dfdffe7a4221d8037b6e2d102467912b0488e237819 |
|
MD5 | 83487f2b5df1e87980fd1cdc64009698 |
|
BLAKE2b-256 | 1484881cebfbc24529f33e50f989bef623c2c8355604a1a67bb792a5a6b6f17c |