conftest.py
This file
Path
tests/conftest.py
30 lines · 720 bytes · Python
Last changed by
Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7
History of this fileTake it
1import asyncio23import pytest4from uvicorn.config import Config5from uvicorn.main import Server678async def app(scope, receive, send):9 assert scope["type"] == "http"10 await send(11 {12 "type": "http.response.start",13 "status": 200,14 "headers": [[b"content-type", b"text/plain"]],15 }16 )17 await send({"type": "http.response.body", "body": b"Hello, world!"})181920@pytest.fixture21async def server():22 config = Config(app=app, lifespan="off")23 server = Server(config=config)24 task = asyncio.ensure_future(server.serve())25 try:26 while not server.started:27 await asyncio.sleep(0.0001)28 yield server29 finally:30 task.cancel()