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 c4b4b75
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions tests/middleware/test_logging.py
@@ -1,4 +1,3 @@
import asyncio
import contextlib
import logging
import socket
Expand Down Expand Up @@ -210,21 +209,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 c4b4b75

Please sign in to comment.