From d9d5c02df851f5dc9692c46b27a787a483c357f1 Mon Sep 17 00:00:00 2001 From: Fedir Zadniprovskyi Date: Sat, 7 Sep 2024 12:14:23 -0700 Subject: [PATCH] deps: add `pytest-async` --- pyproject.toml | 3 ++- tests/conftest.py | 18 +++++++++++++----- tests/sse_test.py | 9 ++++----- uv.lock | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6175a91..9083fdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,8 @@ dev = [ "webvtt-py==0.5.1", "srt==3.5.3", "basedpyright==1.13.0", - "pytest-xdist==3.6.1" + "pytest-xdist==3.6.1", + "pytest-asyncio>=0.24.0", ] [build-system] diff --git a/tests/conftest.py b/tests/conftest.py index a93b1a6..be68a20 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,13 +1,11 @@ -from collections.abc import Generator +from collections.abc import AsyncGenerator, Generator import logging -import os from fastapi.testclient import TestClient +from httpx import ASGITransport, AsyncClient from openai import OpenAI import pytest - -os.environ["WHISPER__MODEL"] = "Systran/faster-whisper-tiny.en" -from faster_whisper_server.main import app +import pytest_asyncio disable_loggers = ["multipart.multipart", "faster_whisper"] @@ -20,10 +18,20 @@ def pytest_configure() -> None: @pytest.fixture() def client() -> Generator[TestClient, None, None]: + from faster_whisper_server.main import app + with TestClient(app) as client: yield client +@pytest_asyncio.fixture() +async def aclient() -> AsyncGenerator[AsyncClient, None]: + from faster_whisper_server.main import app + + async with AsyncClient(transport=ASGITransport(app=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) diff --git a/tests/sse_test.py b/tests/sse_test.py index b672b91..68008ac 100644 --- a/tests/sse_test.py +++ b/tests/sse_test.py @@ -2,17 +2,16 @@ import os from fastapi.testclient import TestClient +from faster_whisper_server.server_models import ( + TranscriptionJsonResponse, + TranscriptionVerboseJsonResponse, +) from httpx_sse import connect_sse import pytest import srt import webvtt import webvtt.vtt -from faster_whisper_server.server_models import ( - TranscriptionJsonResponse, - TranscriptionVerboseJsonResponse, -) - FILE_PATHS = ["audio.wav"] # HACK ENDPOINTS = [ "/v1/audio/transcriptions", diff --git a/uv.lock b/uv.lock index ef37c1a..9b960e9 100644 --- a/uv.lock +++ b/uv.lock @@ -297,6 +297,7 @@ client = [ dev = [ { name = "basedpyright" }, { name = "pytest" }, + { name = "pytest-asyncio" }, { name = "pytest-xdist" }, { name = "ruff" }, { name = "srt" }, @@ -318,6 +319,7 @@ requires-dist = [ { name = "pydantic", specifier = "==2.9.0" }, { name = "pydantic-settings", specifier = "==2.4.0" }, { name = "pytest", marker = "extra == 'dev'", specifier = "==8.3.2" }, + { name = "pytest-asyncio", marker = "extra == 'dev'", specifier = ">=0.24.0" }, { name = "pytest-xdist", marker = "extra == 'dev'", specifier = "==3.6.1" }, { name = "python-multipart", specifier = "==0.0.9" }, { name = "ruff", marker = "extra == 'dev'", specifier = "==0.5.3" }, @@ -3439,6 +3441,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/0f/f9/cf155cf32ca7d6fa3601bc4c5dd19086af4b320b706919d48a4c79081cf9/pytest-8.3.2-py3-none-any.whl", hash = "sha256:4ba08f9ae7dcf84ded419494d229b48d0903ea6407b030eaec46df5e6a73bba5", size = 341802 }, ] +[[package]] +name = "pytest-asyncio" +version = "0.24.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/52/6d/c6cf50ce320cf8611df7a1254d86233b3df7cc07f9b5f5cbcb82e08aa534/pytest_asyncio-0.24.0.tar.gz", hash = "sha256:d081d828e576d85f875399194281e92bf8a68d60d72d1a2faf2feddb6c46b276", size = 49855 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/96/31/6607dab48616902f76885dfcf62c08d929796fc3b2d2318faf9fd54dbed9/pytest_asyncio-0.24.0-py3-none-any.whl", hash = "sha256:a811296ed596b69bf0b6f3dc40f83bcaf341b155a269052d82efa2b25ac7037b", size = 18024 }, +] + [[package]] name = "pytest-xdist" version = "3.6.1"