Skip to content

Instantly share code, notes, and snippets.

@theruziev
Created November 13, 2018 08:09
Show Gist options
  • Save theruziev/e85119f29af31a86bf1968dc8a0b7597 to your computer and use it in GitHub Desktop.
Save theruziev/e85119f29af31a86bf1968dc8a0b7597 to your computer and use it in GitHub Desktop.
aiohttp client fixture with pytest-asyncio compatibility
import pytest
from aiohttp.test_utils import TestServer, TestClient
@pytest.fixture
async def aio_client():
clients = []
async def factory(app):
server = TestServer(app)
client = TestClient(server)
await client.start_server()
clients.append(client)
return client
yield factory
while clients:
await clients.pop().close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment