Skip to content

Commit

Permalink
simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Nov 10, 2022
1 parent d57c4df commit 79678f4
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions tests/middleware/test_logging.py
Expand Up @@ -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

0 comments on commit 79678f4

Please sign in to comment.