1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
import httpx
import pytest
import respx
from respx.fixtures import session_event_loop as event_loop # noqa: F401
pytest_plugins = ["pytester"]
@pytest.fixture()
async def client():
async with httpx.AsyncClient() as client:
yield client
@pytest.fixture()
async def my_mock():
async with respx.mock(
base_url="https://httpx.mock", using="httpcore"
) as respx_mock:
respx_mock.get("/", name="index").respond(404)
yield respx_mock
@pytest.fixture(scope="session")
async def mocked_foo(event_loop): # noqa: F811
async with respx.mock(
base_url="https://foo.api/api/", using="httpcore"
) as respx_mock:
respx_mock.get("/", name="index").respond(202)
respx_mock.get("/bar/", name="bar")
yield respx_mock
@pytest.fixture(scope="session")
async def mocked_ham(event_loop): # noqa: F811
async with respx.mock(base_url="https://ham.api", using="httpcore") as respx_mock:
respx_mock.get("/", name="index").respond(200)
yield respx_mock
|