dep8b_no_network_v2.py
"""Deny all actual network I/O; preserve one intentional localhost-refusal test."""
import socket
import pytest
attempts=[]
def deny(*args,**kwargs):
target=args[0] if args else None
# getaddrinfo(host,port); socket.connect(self,address) never delegated.
if isinstance(target,socket.socket): target=args[1]
elif len(args)>1: target=(args[0],args[1])
attempts.append(target)
raise ConnectionRefusedError('DEP8-b offline gate denies all network')
socket.socket.connect=deny
socket.getaddrinfo=deny
@pytest.fixture(autouse=True)
def record_attempts(request):
before=len(attempts)
yield
new=attempts[before:]
if request.node.nodeid.endswith('test_governance_client.py::test_unreachable_host_is_unavailable_not_refusal'):
assert all(x==('127.0.0.1',1) for x in new), new
else:
assert not new, new