From 26856d8cab398c5a92b2b207be375972c469ce74 Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Mon, 30 Dec 2024 13:35:36 +0200 Subject: [PATCH] another bunch of review fixes --- tests/conftest.py | 16 +++------------- tests/integration_tests/constants.py | 10 ++++++++++ tests/integration_tests/test_chat_completion.py | 15 +++++---------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 91ef722..e37b32b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,27 +4,17 @@ from openai import AsyncAzureOpenAI from aidial_adapter_openai.app import create_app -from aidial_adapter_openai.app_config import ApplicationConfig from aidial_adapter_openai.utils.http_client import DEFAULT_TIMEOUT from aidial_adapter_openai.utils.request import get_app_config -from tests.integration_tests.base import DeploymentConfig, TestDeployments -from tests.integration_tests.constants import TEST_DEPLOYMENTS_CONFIG_PATH +from tests.integration_tests.base import DeploymentConfig +from tests.integration_tests.constants import TEST_DEPLOYMENT_CONFIG @pytest.fixture(scope="session") def _app_instance(): - try: - deployments_config = TestDeployments.from_config( - TEST_DEPLOYMENTS_CONFIG_PATH - ) - except FileNotFoundError: - deployments_config = TestDeployments( - deployments=[], app_config=ApplicationConfig() - ) - return create_app( init_telemetry=False, - app_config=deployments_config.app_config, + app_config=TEST_DEPLOYMENT_CONFIG.app_config, ) diff --git a/tests/integration_tests/constants.py b/tests/integration_tests/constants.py index 40d07dc..efc63ba 100644 --- a/tests/integration_tests/constants.py +++ b/tests/integration_tests/constants.py @@ -1,7 +1,9 @@ import os from pathlib import Path +from aidial_adapter_openai.app_config import ApplicationConfig from aidial_adapter_openai.utils.resource import Resource +from tests.integration_tests.base import TestDeployments CURRENT_DIR = Path(__file__).parent SAMPLE_DOG_IMAGE_PATH = CURRENT_DIR / "images" / "dog-sample-image.png" @@ -13,3 +15,11 @@ "INTEGRATION_TEST_DEPLOYMENTS_CONFIG_PATH", "tests/integration_tests/integration_test_config.json", ) +try: + TEST_DEPLOYMENT_CONFIG = TestDeployments.from_config( + TEST_DEPLOYMENTS_CONFIG_PATH + ) +except FileNotFoundError: + TEST_DEPLOYMENT_CONFIG = TestDeployments( + deployments=[], app_config=ApplicationConfig() + ) diff --git a/tests/integration_tests/test_chat_completion.py b/tests/integration_tests/test_chat_completion.py index 304724c..57d15b1 100644 --- a/tests/integration_tests/test_chat_completion.py +++ b/tests/integration_tests/test_chat_completion.py @@ -1,3 +1,4 @@ +import asyncio import logging import re from typing import Generator, List @@ -5,12 +6,7 @@ import pytest from openai import APIError -from tests.integration_tests.base import ( - TestCase, - TestDeployments, - TestSuite, - TestSuiteBuilder, -) +from tests.integration_tests.base import TestCase, TestSuite, TestSuiteBuilder from tests.integration_tests.chat_completion_suites.text import ( text_common, text_multi_system_messages, @@ -18,7 +14,7 @@ ) from tests.integration_tests.chat_completion_suites.tools import tools_common from tests.integration_tests.chat_completion_suites.vision import vision_common -from tests.integration_tests.constants import TEST_DEPLOYMENTS_CONFIG_PATH +from tests.integration_tests.constants import TEST_DEPLOYMENT_CONFIG from tests.utils.openai import ( ChatCompletionResult, ExpectedException, @@ -32,9 +28,7 @@ def create_test_cases( builders: List[TestSuiteBuilder], ) -> Generator[TestCase, None, None]: for streaming in (False, True): - for deployment in TestDeployments.from_config( - TEST_DEPLOYMENTS_CONFIG_PATH - ).deployments: + for deployment in TEST_DEPLOYMENT_CONFIG.deployments: suite = TestSuite(deployment, streaming) for builder in builders: builder(suite) @@ -78,6 +72,7 @@ async def run_chat_completion() -> ChatCompletionResult: except APIError as e: # Somehow, randomly through test, event loop is closing if e.message == "Event loop is closed": + await asyncio.sleep(5) logger.warning("Event loop is closed, retrying...") continue else: