diff --git a/respx/models.py b/respx/models.py index 39b680b..cb38b17 100644 --- a/respx/models.py +++ b/respx/models.py @@ -52,6 +52,10 @@ def response(self) -> httpx.Response: raise ValueError(f"{self!r} has no response") return self.optional_response + @property + def has_response(self) -> bool: + return self.optional_response is not None + class CallList(list, mock.NonCallableMock): def __init__(self, *args: Sequence[Call], name: Any = "respx") -> None: diff --git a/tests/test_api.py b/tests/test_api.py index 2184d73..8b019d8 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -296,6 +296,7 @@ async def test_raising_content(client): assert route.call_count == 2 assert route.calls.last.request is not None + assert route.calls.last.has_response is False with pytest.raises(ValueError, match="has no response"): assert route.calls.last.response diff --git a/tests/test_remote.py b/tests/test_remote.py index f33af82..a12c229 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -37,7 +37,7 @@ def test_remote_pass_through(using, client_lib, call_count): # pragma: nocover assert response.json()["json"] == {"foo": "bar"} assert respx_mock.calls.last.request.url == url - assert respx_mock.calls.last.response == None # noqa: E711 + assert respx_mock.calls.last.has_response is False assert route.call_count == call_count assert respx_mock.calls.call_count == call_count