Fedir Zadniprovskyi 2024-09-08
deps: add `pytest-async`
@9792549096664c6d7c43e81664e07ad3605de1c7
pyproject.toml
--- pyproject.toml
+++ pyproject.toml
@@ -28,7 +28,8 @@
     "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]
tests/conftest.py
--- tests/conftest.py
+++ 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 @@
 
 @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)
tests/sse_test.py
--- tests/sse_test.py
+++ tests/sse_test.py
@@ -2,16 +2,15 @@
 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 = [
uv.lock
--- uv.lock
+++ uv.lock
@@ -297,6 +297,7 @@
 dev = [
     { name = "basedpyright" },
     { name = "pytest" },
+    { name = "pytest-asyncio" },
     { name = "pytest-xdist" },
     { name = "ruff" },
     { name = "srt" },
@@ -318,6 +319,7 @@
     { 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" },
@@ -3440,6 +3442,18 @@
 ]
 
 [[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"
 source = { registry = "https://pypi.org/simple" }
Add a comment
List