From 9f9074fd1caf9b41da997407ff45dff917f0b092 Mon Sep 17 00:00:00 2001 From: Wouter Klouwen Date: Tue, 13 Feb 2024 17:52:02 +0000 Subject: [PATCH] HTTPServerBase: change Request to be more verbose respond_nohandler When a Request is not handled and thus triggers the nohandler, it can be very useful to have a more verbose output to indicate which Request is unhandled. --- pytest_httpserver/httpserver.py | 4 ++-- tests/test_blocking_httpserver.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pytest_httpserver/httpserver.py b/pytest_httpserver/httpserver.py index 2c24ba8..04581ee 100644 --- a/pytest_httpserver/httpserver.py +++ b/pytest_httpserver/httpserver.py @@ -821,9 +821,9 @@ def respond_nohandler(self, request: Request, extra_message: str = ""): As the result, there's an assertion added (which can be raised by :py:meth:`check_assertions`). """ - text = "No handler found for request {!r}.\n".format(request) + text = "No handler found for request {!r} with data {!r}.".format(request, request.data) self.add_assertion(text + extra_message) - return Response("No handler found for this request", self.no_handler_status_code) + return Response(text + extra_message, self.no_handler_status_code) @abc.abstractmethod def dispatch(self, request: Request) -> Response: diff --git a/tests/test_blocking_httpserver.py b/tests/test_blocking_httpserver.py index 7fbea11..88d0709 100644 --- a/tests/test_blocking_httpserver.py +++ b/tests/test_blocking_httpserver.py @@ -97,7 +97,10 @@ def test_ignores_when_request_is_not_asserted(httpserver: BlockingHTTPServer): ) with when_a_request_is_being_sent_to_the_server(request) as server_connection: - assert server_connection.get(timeout=9).text == "No handler found for this request" + assert ( + server_connection.get(timeout=9).text + == f"No handler found for request with data b''." + ) def test_raises_assertion_error_when_request_was_not_responded(httpserver: BlockingHTTPServer):