conftest.py
This file
Path
tests/conftest.py
34 lines · 747 bytes · Python
Last changed by
ConnectionsTom Christiebefore adoption86263fa
History of this fileTake it
ConnectionsTom Christiebefore adoption86263fa
lines 1–34why, one step back1import asyncio2import json34import pytest5from uvicorn.config import Config6from uvicorn.main import Server789async def app(scope, receive, send):10 assert scope['type'] == 'http'11 await send({12 'type': 'http.response.start',13 'status': 200,14 'headers': [15 [b'content-type', b'text/plain'],16 ]17 })18 await send({19 'type': 'http.response.body',20 'body': b'Hello, world!',21 })222324@pytest.fixture25async def server():26 config = Config(app=app, lifespan="off")27 server = Server(config=config)28 task = asyncio.ensure_future(server.serve())29 try:30 while not server.started:31 await asyncio.sleep(0.0001)32 yield server33 finally:34 task.cancel()