Skip to content

Commit d505f17

Browse files
azmeukcsernazs
authored andcommitted
Implemented BaseHTTPServer.__repr__
1 parent 155918b commit d505f17

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

pytest_httpserver/httpserver.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ def __init__(
611611
self.ssl_context = ssl_context
612612
self.no_handler_status_code = 500
613613

614+
def __repr__(self):
615+
return f"<{self.__class__.__name__} host={self.host} port={self.port}>"
616+
614617
def clear(self):
615618
"""
616619
Clears and resets the state attributes of the object.

tests/test_blocking_httpserver.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ def test_raises_assertion_error_when_request_was_not_responded(httpserver: Block
120120

121121
assert "/my/path" in str(exc)
122122
assert "no response" in str(exc).lower()
123+
124+
125+
def test_repr(httpserver: BlockingHTTPServer):
126+
assert repr(httpserver) == f"<BlockingHTTPServer host=localhost port={httpserver.port}>"

tests/test_mixed.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,7 @@ def test_all_ordered_missing(httpserver: HTTPServer):
8282
assert len(httpserver.ordered_handlers) == 2
8383
assert len(httpserver.oneshot_handlers) == 2
8484
assert len(httpserver.handlers) == 1
85+
86+
87+
def test_repr(httpserver: HTTPServer):
88+
assert repr(httpserver) == f"<HTTPServer host=localhost port={httpserver.port}>"

0 commit comments

Comments
 (0)