-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
63 lines (46 loc) · 1.69 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from __future__ import annotations
import os
import asyncio
import logging
from typing import TYPE_CHECKING, Iterator, AsyncIterator
import pytest
from finch import Finch, AsyncFinch
if TYPE_CHECKING:
from _pytest.fixtures import FixtureRequest
pytest.register_assert_rewrite("tests.utils")
logging.getLogger("finch").setLevel(logging.DEBUG)
@pytest.fixture(scope="session")
def event_loop() -> Iterator[asyncio.AbstractEventLoop]:
loop = asyncio.new_event_loop()
yield loop
loop.close()
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
access_token = "My Access Token"
client_id = "4ab15e51-11ad-49f4-acae-f343b7794375"
client_secret = "My Client Secret"
@pytest.fixture(scope="session")
def client(request: FixtureRequest) -> Iterator[Finch]:
strict = getattr(request, "param", True)
if not isinstance(strict, bool):
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
with Finch(
base_url=base_url,
access_token=access_token,
client_id=client_id,
client_secret=client_secret,
_strict_response_validation=strict,
) as client:
yield client
@pytest.fixture(scope="session")
async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncFinch]:
strict = getattr(request, "param", True)
if not isinstance(strict, bool):
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
async with AsyncFinch(
base_url=base_url,
access_token=access_token,
client_id=client_id,
client_secret=client_secret,
_strict_response_validation=strict,
) as client:
yield client