You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Listen on custom address in AsyncHTTPTestCase #2969
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?
Not currently. It's a three-line method so you could just copy it and modify as needed. Or I wouldn't mind a PR adding a keyword argument to control the address.
Activity
bdarnell commentedon Jan 9, 2021
Not currently. It's a three-line method so you could just copy it and modify as needed. Or I wouldn't mind a PR adding a keyword argument to control the address.
Add 'address' keyword control binded address tornadoweb#2969
youguanxinqing commentedon Jan 11, 2021
#2974
Merge pull request #2974 from youguanxinqing/issue-2969
bdarnell commentedon Feb 4, 2021
Fixed in #2974
PR (#1)
Add 'address' keyword control binded address tornadoweb#2969