Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brings lifespan to 100% coverage #897

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tests/test_lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,13 @@ async def test():

@pytest.mark.parametrize("mode", ("auto", "on"))
@pytest.mark.parametrize("raise_exception", (True, False))
def test_lifespan_with_failed_startup(mode, raise_exception):
def test_lifespan_with_failed_startup(mode, raise_exception, caplog):
async def app(scope, receive, send):
message = await receive()
assert message["type"] == "lifespan.startup"
await send({"type": "lifespan.startup.failed"})
await send(
{"type": "lifespan.startup.failed", "message": "the lifespan event failed"}
)
if raise_exception:
# App should be able to re-raise an exception if startup failed.
raise RuntimeError()
Expand All @@ -144,6 +146,13 @@ async def test():

loop = asyncio.new_event_loop()
loop.run_until_complete(test())
error_messages = [
record.message
for record in caplog.records
if record.name == "uvicorn.error" and record.levelname == "ERROR"
]
assert "the lifespan event failed" in error_messages.pop(0)
assert "Application startup failed. Exiting." in error_messages.pop(0)


@pytest.mark.parametrize("mode", ("auto", "on"))
Expand Down