From e94249624c3252c06471b89d19b025b9f345a9e5 Mon Sep 17 00:00:00 2001 From: Joe Tsoi Date: Thu, 25 Feb 2021 11:05:33 +0000 Subject: [PATCH] Allow AF_UNIX sockets in GuardedSocket asyncio uses unix domain sockets, as we're mainly interested in blocking external requests, allowing AF_UNIX through should be fine. --- pytest_socket.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pytest_socket.py b/pytest_socket.py index 0c8dd63..4e48643 100644 --- a/pytest_socket.py +++ b/pytest_socket.py @@ -77,7 +77,10 @@ def disable_socket(): class GuardedSocket(socket.socket): """ socket guard to disable socket creation (from pytest-socket) """ def __new__(cls, *args, **kwargs): - raise SocketBlockedError() + if args[0] != socket.AddressFamily.AF_UNIX: + raise SocketBlockedError() + return super().__new__(cls, *args, **kwargs) + socket.socket = GuardedSocket