def assert_ip(ip): port = reserve(ip) # show that we can't bind to it without SO_REUSEADDR error = bind_naive(ip, port) assert error and error.errno == errno.EADDRINUSE, error # show that we *can* bind to it without SO_REUSEADDR, after release sock = bind_reuse(ip, port) sname = sock.getsockname() assert sname == (ip, port), (sname, port)
def pypi_port(): yield reserve()