lundberg / respx

Mock HTTPX with awesome request patterns and response side effects 🦋
https://lundberg.github.io/respx
BSD 3-Clause "New" or "Revised" License
581 stars 38 forks source link

Consider a router option to define default response #227

Open lundberg opened 1 year ago

lundberg commented 1 year ago

As discussed in https://github.com/lundberg/respx/issues/177#issuecomment-1399321666 .

By default, respx responds with a httpx.Resopnse(200) when no mocked route is matched and assert_all_mocked is disabled.

The idea is to allow the router to take a default mock option to override that.

e.g.

mock_api = respx.mock(base_url="https://example.com/", default_mock=httpx.Response(404))

@mock_api
def test_example():
    response = httpx.get("https://example.com/some/path/")
    assert response.status_code == 404

By setting this option, assert_all_mocked should probably be forced disabled.