diff --git a/httpretty/core.py b/httpretty/core.py index 83133545..e1e9ebab 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -395,6 +395,13 @@ def __init__( self.is_http = False self._bufsize = 32 * 1024 + def __enter__(self): + return self + + def __exit__(self, *args): + if not self._closed: + self.close() + def create_socket(self): return old_socket(self.socket_family, self.socket_type, self.socket_proto)