diff --git a/tests/middleware/test_logging.py b/tests/middleware/test_logging.py index 5d3c3a1eca..58bf8a1fbd 100644 --- a/tests/middleware/test_logging.py +++ b/tests/middleware/test_logging.py @@ -210,21 +210,11 @@ async def app(scope, receive, send): @pytest.mark.anyio -async def test_server_start_with_port_zero(caplog): +async def test_server_start_with_port_zero(caplog: pytest.LogCaptureFixture): config = Config(app=app, port=0) - with caplog_for_logger(caplog, "uvicorn.access"): - async with run_server(config) as server: - while not server.started: - await asyncio.sleep(0.1) - for s in server.servers: - for sock in s.sockets: - host, port = sock.getsockname() - messages = [ - record.message for record in caplog.records if "uvicorn" in record.name - ] - assert "Started server process" in messages.pop(0) - assert "Waiting for application startup" in messages.pop(0) - assert "ASGI 'lifespan' protocol appears unsupported" in messages.pop(0) - assert "Application startup complete" in messages.pop(0) - assert f"Uvicorn running on http://{host}:{port}" in messages.pop(0) - assert "Shutting down" in messages.pop(0) + async with run_server(config) as server: + server = server.servers[0] + sock = server.sockets[0] + host, port = sock.getsockname() + messages = [record.message for record in caplog.records if "uvicorn" in record.name] + assert f"Uvicorn running on http://{host}:{port} (Press CTRL+C to quit)" in messages