Skip to content
Myr

conftest.py

This file

Path

tests/conftest.py

32 lines · 784 bytes · Python

Last changed by

Merge pull request #4 from encode/connection-poolingTom Christiebefore adoption68c468a

History of this file

Take it

Merge pull request #1 from encode/add-connectionsTom Christiebefore adoption7626fe7

lines 1–29why, one step back
1import asyncio
23import 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:

Merge pull request #4 from encode/connection-poolingTom Christiebefore adoption68c468a

lines 30–32why, one step back
30 server.should_exit = True
31 server.force_exit = True32 await task