@@ -50,22 +50,24 @@ class LiveServer(object):
5050 stopping application in a separate process.
5151
5252 :param app: The application to run.
53+ :param host: The host where to listen (default localhost).
5354 :param port: The port to run application.
5455 """
5556
56- def __init__ (self , app , port , clean_stop = False ):
57+ def __init__ (self , app , host , port , clean_stop = False ):
5758 self .app = app
5859 self .port = port
60+ self .host = host
5961 self .clean_stop = clean_stop
6062 self ._process = None
6163
6264 def start (self ):
6365 """Start application in a separate process."""
64- def worker (app , port ):
65- app .run (port = port , use_reloader = False , threaded = True )
66+ def worker (app , host , port ):
67+ app .run (host = host , port = port , use_reloader = False , threaded = True )
6668 self ._process = multiprocessing .Process (
6769 target = worker ,
68- args = (self .app , self .port )
70+ args = (self .app , self .host , self . port )
6971 )
7072 self ._process .start ()
7173
@@ -82,7 +84,7 @@ def worker(app, port):
8284
8385 def url (self , url = '' ):
8486 """Returns the complete url based on server options."""
85- return 'http://localhost :%d%s' % (self .port , url )
87+ return 'http://%s :%d%s' % (self . host , self .port , url )
8688
8789 def stop (self ):
8890 """Stop application process."""
@@ -143,14 +145,16 @@ def test_server_is_up_and_running(live_server):
143145 port = s .getsockname ()[1 ]
144146 s .close ()
145147
148+ host = pytestconfig .getvalue ('live_server_host' )
149+
146150 # Explicitly set application ``SERVER_NAME`` for test suite
147151 # and restore original value on test teardown.
148152 server_name = app .config ['SERVER_NAME' ] or 'localhost'
149153 monkeypatch .setitem (app .config , 'SERVER_NAME' ,
150154 _rewrite_server_name (server_name , str (port )))
151155
152156 clean_stop = request .config .getvalue ('live_server_clean_stop' )
153- server = LiveServer (app , port , clean_stop )
157+ server = LiveServer (app , host , port , clean_stop )
154158 if request .config .getvalue ('start_live_server' ):
155159 server .start ()
156160
0 commit comments