I need to run a test and listen on 0.0.0.0 to allow an external service to connect through another IP, but the default one is 127.0.0.1.
In testing.py:
defbind_unused_port(reuse_port: bool=False) ->Tuple[socket.socket, int]:
"""Binds a server socket to an available port on localhost. Returns a tuple (socket, port). .. versionchanged:: 4.4 Always binds to ``127.0.0.1`` without resolving the name ``localhost``. """sock=netutil.bind_sockets(
0, "127.0.0.1", family=socket.AF_INET, reuse_port=reuse_port
)[0]
port=sock.getsockname()[1]
returnsock, port
Is there a clean way of listening on 0.0.0.0 in a test?
I need to run a test and listen on
0.0.0.0to allow an external service to connect through another IP, but the default one is127.0.0.1.In
testing.py:Is there a clean way of listening on
0.0.0.0in a test?