@@ -50,22 +50,24 @@ class LiveServer(object):
50
50
stopping application in a separate process.
51
51
52
52
:param app: The application to run.
53
+ :param host: The host where to listen (default localhost).
53
54
:param port: The port to run application.
54
55
"""
55
56
56
- def __init__ (self , app , port , clean_stop = False ):
57
+ def __init__ (self , app , host , port , clean_stop = False ):
57
58
self .app = app
58
59
self .port = port
60
+ self .host = host
59
61
self .clean_stop = clean_stop
60
62
self ._process = None
61
63
62
64
def start (self ):
63
65
"""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 )
66
68
self ._process = multiprocessing .Process (
67
69
target = worker ,
68
- args = (self .app , self .port )
70
+ args = (self .app , self .host , self . port )
69
71
)
70
72
self ._process .start ()
71
73
@@ -82,7 +84,7 @@ def worker(app, port):
82
84
83
85
def url (self , url = '' ):
84
86
"""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 )
86
88
87
89
def stop (self ):
88
90
"""Stop application process."""
@@ -143,14 +145,16 @@ def test_server_is_up_and_running(live_server):
143
145
port = s .getsockname ()[1 ]
144
146
s .close ()
145
147
148
+ host = pytestconfig .getvalue ('live_server_host' )
149
+
146
150
# Explicitly set application ``SERVER_NAME`` for test suite
147
151
# and restore original value on test teardown.
148
152
server_name = app .config ['SERVER_NAME' ] or 'localhost'
149
153
monkeypatch .setitem (app .config , 'SERVER_NAME' ,
150
154
_rewrite_server_name (server_name , str (port )))
151
155
152
156
clean_stop = request .config .getvalue ('live_server_clean_stop' )
153
- server = LiveServer (app , port , clean_stop )
157
+ server = LiveServer (app , host , port , clean_stop )
154
158
if request .config .getvalue ('start_live_server' ):
155
159
server .start ()
156
160
0 commit comments