Skip to content

Conversation

dhrod5
Copy link

@dhrod5 dhrod5 commented Jun 29, 2018

…e selenium server

My usecase was that I wanted to have testing done using docker compose and selenium/standalone-chrome. Since they run in different containers you need to bind the host to 0.0.0.0 or the selenium container cannot access the LiveServer.

These changes allow you to configure your app to change the host that the LiveServer starts on like this:

def create_app(self): app.config.update( LIVESERVER_PORT=8943, LIVESERVER_HOST='0.0.0.0' )

@@ -453,7 +454,7 @@ def get_server_url(self):
"""
Return the url of the test server
"""
return 'http://localhost:%s' % self._port_value.value
return 'http://{}:{}'.format(self._configured_host, self._port_value.value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To pass python2.6 testing, line should be apparently something more like

return 'http://{hostname}:{port}'.format(
    hostname=self._configured_host,
    port=self._port_value.value,
)

@@ -477,7 +478,7 @@ def socket_bind_wrapper(self):
return ret

socketserver.TCPServer.server_bind = socket_bind_wrapper
app.run(port=port, use_reloader=False)
app.run(port=port, use_reloader=False, host=self._configured_host)

self._process = multiprocessing.Process(
target=worker, args=(self.app, self._configured_port)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably also add the parameters here:

self._process = multiprocessing.Process(
    target=worker, args=(self.app, self._configured_host, self._configured_port)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And of course https://github.com/jarus/flask-testing/pull/126/files#diff-171a436f5b46787445201095ddb2db3fR463 will have to become

def worker(app, host, port):

Copy link

@nelsnelson nelsnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -477,7 +478,7 @@ def socket_bind_wrapper(self):
return ret

socketserver.TCPServer.server_bind = socket_bind_wrapper
app.run(port=port, use_reloader=False)
app.run(port=port, use_reloader=False, host=self._configured_host)

self._process = multiprocessing.Process(
target=worker, args=(self.app, self._configured_port)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And of course https://github.com/jarus/flask-testing/pull/126/files#diff-171a436f5b46787445201095ddb2db3fR463 will have to become

def worker(app, host, port):

@@ -477,7 +478,7 @@ def socket_bind_wrapper(self):
return ret

socketserver.TCPServer.server_bind = socket_bind_wrapper
app.run(port=port, use_reloader=False)
app.run(port=port, use_reloader=False, host=self._configured_host)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameterize the worker method so that this can be simply host=host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants