forked from HENNGE/aiodynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
37 lines (29 loc) · 1.1 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import asyncio
from asyncio import AbstractEventLoop
from typing import AsyncGenerator, Generator
import pytest
from _pytest.fixtures import SubRequest
from aiodynamo.http.types import HttpImplementation
@pytest.fixture(params=["httpx", "aiohttp"])
async def http(request: SubRequest) -> AsyncGenerator[HttpImplementation, None]:
if request.param == "httpx":
try:
import httpx
from aiodynamo.http.httpx import HTTPX
except ImportError:
raise pytest.skip("httpx not installed")
async with httpx.AsyncClient() as client:
yield HTTPX(client)
elif request.param == "aiohttp":
try:
import aiohttp
from aiodynamo.http.aiohttp import AIOHTTP
except ImportError:
raise pytest.skip("aiohttp not installed")
async with aiohttp.ClientSession() as session:
yield AIOHTTP(session)
@pytest.fixture(scope="session")
def session_event_loop() -> Generator[AbstractEventLoop, None, None]:
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()