Created
November 13, 2018 08:09
-
-
Save theruziev/e85119f29af31a86bf1968dc8a0b7597 to your computer and use it in GitHub Desktop.
aiohttp client fixture with pytest-asyncio compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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