Skip to content

Commit

Permalink
Add test case for port being zero (#1758)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
  • Loading branch information
iudeen and Kludex committed Nov 10, 2022
1 parent a901031 commit de0a23a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -82,7 +82,7 @@ plugins =

[coverage:report]
precision = 2
fail_under = 98.30
fail_under = 98.28
show_missing = true
skip_covered = true
exclude_lines =
Expand Down
11 changes: 11 additions & 0 deletions tests/middleware/test_logging.py
Expand Up @@ -206,3 +206,14 @@ async def app(scope, receive, send):
if record.name == "uvicorn.access"
]
assert '"GET / HTTP/1.1" 599' in messages.pop()


@pytest.mark.anyio
async def test_server_start_with_port_zero(caplog: pytest.LogCaptureFixture):
config = Config(app=app, port=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 de0a23a

Please sign in to comment.