File size: 1,112 Bytes
f3d078e
313814b
bf48682
81fa68b
 
bf48682
f3d078e
5aa421e
dc4f25f
f3d078e
313814b
 
 
 
dc4f25f
313814b
 
 
81fa68b
 
 
 
bf48682
 
81fa68b
5aa421e
 
f3d078e
 
bf48682
 
f3d078e
 
 
5aa421e
 
 
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
from collections.abc import AsyncGenerator, Generator
import logging
import os

from fastapi.testclient import TestClient
from faster_whisper_server.main import create_app
from httpx import ASGITransport, AsyncClient
from openai import OpenAI
import pytest
import pytest_asyncio

disable_loggers = ["multipart.multipart", "faster_whisper"]


def pytest_configure() -> None:
    for logger_name in disable_loggers:
        logger = logging.getLogger(logger_name)
        logger.disabled = True


@pytest.fixture()
def client() -> Generator[TestClient, None, None]:
    os.environ["WHISPER__MODEL"] = "Systran/faster-whisper-tiny.en"
    with TestClient(create_app()) as client:
        yield client


@pytest_asyncio.fixture()
async def aclient() -> AsyncGenerator[AsyncClient, None]:
    os.environ["WHISPER__MODEL"] = "Systran/faster-whisper-tiny.en"
    async with AsyncClient(transport=ASGITransport(app=create_app()), base_url="http://test") as aclient:
        yield aclient


@pytest.fixture()
def openai_client(client: TestClient) -> OpenAI:
    return OpenAI(api_key="cant-be-empty", http_client=client)