Skip to content

Commit cc493bd

Browse files
committed
Move out function definition from live_server fixture
1 parent 4612587 commit cc493bd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pytest_flask/fixtures.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ def __repr__(self):
8686
return '<LiveServer listening at %s>' % self.url()
8787

8888

89+
def _rewrite_server_name(server_name, new_port):
90+
"""Rewrite server port in ``server_name`` with ``new_port`` value."""
91+
sep = ':'
92+
if sep in server_name:
93+
server_name, port = server_name.split(sep, 1)
94+
return sep.join((server_name, new_port))
95+
96+
8997
@pytest.fixture(scope='function')
9098
def live_server(request, app, monkeypatch):
9199
"""Run application in a separate process.
@@ -107,18 +115,11 @@ def test_server_is_up_and_running(live_server):
107115
port = s.getsockname()[1]
108116
s.close()
109117

110-
def rewrite_server_name(server_name, new_port):
111-
"""Rewrite server port in ``server_name`` with ``new_port`` value."""
112-
sep = ':'
113-
if sep in server_name:
114-
server_name, port = server_name.split(sep, 1)
115-
return sep.join((server_name, new_port))
116-
117118
# Explicitly set application ``SERVER_NAME`` for test suite
118119
# and restore original value on test teardown.
119120
server_name = app.config['SERVER_NAME'] or 'localhost'
120121
monkeypatch.setitem(app.config, 'SERVER_NAME',
121-
rewrite_server_name(server_name, str(port)))
122+
_rewrite_server_name(server_name, str(port)))
122123

123124
server = LiveServer(app, port)
124125
request.addfinalizer(server.stop)

0 commit comments

Comments
 (0)