diff --git a/pytest_socket.py b/pytest_socket.py index 22bdc71..b138c8e 100644 --- a/pytest_socket.py +++ b/pytest_socket.py @@ -12,18 +12,11 @@ class SocketBlockedError(RuntimeError): - def __init__(self, *_args, **_kwargs): - super().__init__("A test tried to use socket.socket.") + pass class SocketConnectBlockedError(RuntimeError): - def __init__(self, allowed, host, *_args, **_kwargs): - if allowed: - allowed = ",".join(allowed) - super().__init__( - "A test tried to use socket.socket.connect() " - f'with host "{host}" (allowed: "{allowed}").' - ) + pass def pytest_addoption(parser): @@ -100,7 +93,7 @@ def __new__(cls, family=-1, type=-1, proto=-1, fileno=None): if _is_unix_socket(family) and allow_unix_socket: return super().__new__(cls, family, type, proto, fileno) - raise SocketBlockedError() + raise SocketBlockedError("A test tried to use socket.socket.") socket.socket = GuardedSocket @@ -283,7 +276,12 @@ def guarded_connect(inst, *args): ): return _true_connect(inst, *args) - raise SocketConnectBlockedError(allowed_list, host) + allowed = ",".join(allowed_list) if allowed_list else "[]" + message = ( + "A test tried to use socket.socket.connect() " + f'with host "{host}" (allowed: "{allowed}").' + ) + raise SocketConnectBlockedError(message) socket.socket.connect = guarded_connect