Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions tests/python/unit/validation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import asyncio
from contextlib import AsyncExitStack
from functools import partial

import pytest
Expand All @@ -27,7 +28,7 @@

@pytest.fixture(scope="session")
def event_loop():
"""Override default event loop fixture to make it module-level"""
"""Provide a session-scoped event loop for async validation tests"""
loop = asyncio.new_event_loop()
yield loop
loop.close()
Expand Down Expand Up @@ -56,13 +57,19 @@ def oai_llm_service(oai_async_azure_client):


@pytest.fixture(scope="session", autouse=True)
async def running_openai_service(oai_llm_service):
def running_openai_service(oai_llm_service, event_loop):
"""Set up running OpenAI service to use for tests"""
if os.getenv("AZURE_OPENAI_API_KEY") is None:
yield
else:
async with RunningAsyncServices([oai_llm_service]):
yield
return

manager = RunningAsyncServices([oai_llm_service])
stack = AsyncExitStack()
event_loop.run_until_complete(stack.enter_async_context(manager))
try:
yield
finally:
event_loop.run_until_complete(stack.aclose())


@pytest.fixture(scope="session")
Expand Down
Loading
Loading