Skip to content

Commit

Permalink
HTTPServerBase: change Request to be more verbose respond_nohandler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wouterklouwen-youview authored and dublet committed Feb 15, 2024
1 parent f2ee166 commit 9f9074f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pytest_httpserver/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_blocking_httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Request 'http://localhost:{httpserver.port}/my/path' [GET]> with data b''."
)


def test_raises_assertion_error_when_request_was_not_responded(httpserver: BlockingHTTPServer):
Expand Down

0 comments on commit 9f9074f

Please sign in to comment.