

test: switch to async openai client
@e76455d55b48e33a6f5aa083dfeb8f893ed45edf
--- tests/api_model_test.py
+++ tests/api_model_test.py
... | ... | @@ -1,5 +1,5 @@ |
1 | 1 |
import openai |
2 |
-from openai import OpenAI |
|
2 |
+from openai import AsyncOpenAI |
|
3 | 3 |
import pytest |
4 | 4 |
|
5 | 5 |
MODEL_THAT_EXISTS = "Systran/faster-whisper-tiny.en" |
... | ... | @@ -7,16 +7,19 @@ |
7 | 7 |
MIN_EXPECTED_NUMBER_OF_MODELS = 70 # At the time of the test creation there are 89 models |
8 | 8 |
|
9 | 9 |
|
10 |
-def test_list_models(openai_client: OpenAI) -> None: |
|
11 |
- models = openai_client.models.list().data |
|
10 |
+@pytest.mark.asyncio() |
|
11 |
+async def test_list_models(openai_client: AsyncOpenAI) -> None: |
|
12 |
+ models = (await openai_client.models.list()).data |
|
12 | 13 |
assert len(models) > MIN_EXPECTED_NUMBER_OF_MODELS |
13 | 14 |
|
14 | 15 |
|
15 |
-def test_model_exists(openai_client: OpenAI) -> None: |
|
16 |
- model = openai_client.models.retrieve(MODEL_THAT_EXISTS) |
|
16 |
+@pytest.mark.asyncio() |
|
17 |
+async def test_model_exists(openai_client: AsyncOpenAI) -> None: |
|
18 |
+ model = await openai_client.models.retrieve(MODEL_THAT_EXISTS) |
|
17 | 19 |
assert model.id == MODEL_THAT_EXISTS |
18 | 20 |
|
19 | 21 |
|
20 |
-def test_model_does_not_exist(openai_client: OpenAI) -> None: |
|
22 |
+@pytest.mark.asyncio() |
|
23 |
+async def test_model_does_not_exist(openai_client: AsyncOpenAI) -> None: |
|
21 | 24 |
with pytest.raises(openai.NotFoundError): |
22 |
- openai_client.models.retrieve(MODEL_THAT_DOES_NOT_EXIST) |
|
25 |
+ await openai_client.models.retrieve(MODEL_THAT_DOES_NOT_EXIST) |
--- tests/conftest.py
+++ tests/conftest.py
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 |
from fastapi.testclient import TestClient |
6 | 6 |
from faster_whisper_server.main import create_app |
7 | 7 |
from httpx import ASGITransport, AsyncClient |
8 |
-from openai import AsyncOpenAI, OpenAI |
|
8 |
+from openai import AsyncOpenAI |
|
9 | 9 |
import pytest |
10 | 10 |
import pytest_asyncio |
11 | 11 |
|
... | ... | @@ -32,9 +32,9 @@ |
32 | 32 |
yield aclient |
33 | 33 |
|
34 | 34 |
|
35 |
-@pytest.fixture() |
|
36 |
-def openai_client(client: TestClient) -> OpenAI: |
|
37 |
- return OpenAI(api_key="cant-be-empty", http_client=client) |
|
35 |
+@pytest_asyncio.fixture() |
|
36 |
+def openai_client(aclient: AsyncClient) -> AsyncOpenAI: |
|
37 |
+ return AsyncOpenAI(api_key="cant-be-empty", http_client=aclient) |
|
38 | 38 |
|
39 | 39 |
|
40 | 40 |
@pytest.fixture() |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?