Skip to content

Commit 10373ac

Browse files
committed
set tmp_path only
1 parent d67169f commit 10373ac

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

tests/fixtures.py

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def qtbot(qtbot, fail_if_open_message_boxes_left, close_remaining_widgets):
8383
qtbot.wait(5000)
8484

8585

86+
@pytest.fixture
87+
def msui_configs(tmp_path):
88+
modify_config_file({"mss_dir": tmp_path.name})
89+
90+
8691
@pytest.fixture(scope="session")
8792
def mscolab_session_app():
8893
"""Session-scoped fixture that provides the WSGI app instance for MSColab.
@@ -141,11 +146,6 @@ def reset_mscolab(mscolab_session_app):
141146
handle_db_reset()
142147

143148

144-
@pytest.fixture(scope="session")
145-
def msui_configs(tmp_path):
146-
modify_config_file({"mss_dir": tmp_path.name})
147-
148-
149149
@pytest.fixture
150150
def mscolab_app(mscolab_session_app, reset_mscolab):
151151
"""Fixture that provides the MSColab WSGI app instance and does cleanup actions.
@@ -196,60 +196,20 @@ def _running_eventlet_server(app):
196196
"""Context manager that starts the app in an eventlet server and returns its URL."""
197197
scheme = "http"
198198
host = "127.0.0.1"
199-
199+
socket = eventlet.listen((host, 0))
200+
port = socket.getsockname()[1]
201+
url = f"{scheme}://{host}:{port}"
202+
app.config['URL'] = url
200203
if "fork" not in multiprocessing.get_all_start_methods():
201204
pytest.skip("requires the multiprocessing start_method 'fork', which is unavailable on this system")
202-
203205
ctx = multiprocessing.get_context("fork")
204-
205-
def _serve_in_child(conn, _app, _host, _scheme):
206-
# Create the listening socket inside the child to avoid passing GreenSocket/FD across fork.
207-
sock = eventlet.listen((_host, 0))
208-
port = sock.getsockname()[1]
209-
url = f"{_scheme}://{_host}:{port}"
210-
211-
try:
212-
_app.config["URL"] = url
213-
except Exception:
214-
# If app/config is not writable for some reason, still start server.
215-
pass
216-
217-
conn.send(port)
218-
conn.close()
219-
220-
# Run until terminated by parent.
221-
eventlet.wsgi.server(sock, _app)
222-
223-
parent_conn, child_conn = ctx.Pipe(duplex=False)
224-
process = ctx.Process(target=_serve_in_child, args=(child_conn, app, host, scheme), daemon=True)
225-
206+
process = ctx.Process(target=eventlet.wsgi.server, args=(socket, app), daemon=True)
226207
try:
227208
process.start()
228-
229-
# Wait for the child to report the bound port.
230-
if not parent_conn.poll(5):
231-
raise RuntimeError("Server did not report its port within 5 seconds")
232-
port = parent_conn.recv()
233-
234-
url = f"{scheme}://{host}:{port}"
235-
app.config["URL"] = url
236-
237-
start_time = time.time()
238-
sleep_time = 0.01
239209
while not is_url_response_ok(urllib.parse.urljoin(url, "index")):
240-
if (time.time() - start_time) > 5:
241-
raise RuntimeError(f"Server did not start within 5 seconds at {url}")
242-
time.sleep(sleep_time)
243-
sleep_time *= 2
244-
if sleep_time > 1:
245-
sleep_time = 1
246-
210+
time.sleep(0.5)
247211
yield url
248212
finally:
249-
try:
250-
parent_conn.close()
251-
except Exception:
252-
pass
253213
process.terminate()
254214
process.join(10)
255215
process.close()

0 commit comments

Comments
 (0)