lundberg/respx
Fork: 38 Star: 512 (更新于 1970-01-01 00:00:00)
license: BSD-3-Clause
Language: Python .
Mock HTTPX with awesome request patterns and response side effects 🦋
最后发布版本: 0.20.2 ( 2023-07-21 07:05:54)
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.
最近版本更新:(数据更新于 1970-01-01 00:00:00)
2023-07-21 07:05:54 0.20.2
2022-11-19 01:03:03 0.20.1
2022-09-16 17:30:49 0.20.0
2022-09-14 18:03:04 0.19.3
2022-02-03 18:28:04 0.19.2
2022-01-10 18:13:43 0.19.1
2021-11-15 23:43:57 0.19.0
2021-10-22 15:26:07 0.18.2
2021-10-21 00:27:20 0.18.1
2021-10-14 21:38:06 0.18.0
主题(topics):
httpx, mock, pytest, testing
lundberg/respx同语言 Python最近更新仓库
2024-12-22 18:18:34 LeslieLeung/heimdallr
2024-12-22 09:03:32 ultralytics/ultralytics
2024-12-21 13:26:40 notepad-plus-plus/nppPluginList
2024-12-21 11:42:53 XiaoMi/ha_xiaomi_home
2024-12-21 04:33:22 comfyanonymous/ComfyUI
2024-12-20 18:47:56 home-assistant/core