Update test_search_db.py

This commit is contained in:
hajdul88 2025-12-11 20:41:01 +01:00
parent d1a3928d7e
commit 043a2da1aa

View file

@ -1,8 +1,11 @@
import pathlib import pathlib
import os import os
import warnings
import pytest import pytest
import pytest_asyncio import pytest_asyncio
import cognee import cognee
from cognee.infrastructure.databases.graph import get_graph_engine from cognee.infrastructure.databases.graph import get_graph_engine
from cognee.infrastructure.databases.vector import get_vector_engine from cognee.infrastructure.databases.vector import get_vector_engine
from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge
@ -46,6 +49,27 @@ async def cleanup_litellm_clients():
pass pass
@pytest_asyncio.fixture(scope="session", autouse=True)
async def cleanup_litellm_clients_session():
"""Session-scoped fixture to cleanup LiteLLM clients at the end of all tests.
This ensures cleanup happens before LiteLLM's own cleanup tries to run
during event loop closure, preventing RuntimeWarning in Python 3.10.
"""
yield
# Final cleanup of LiteLLM async clients at session end
try:
import litellm
if hasattr(litellm, "close_litellm_async_clients"):
cleanup_coro = litellm.close_litellm_async_clients()
if cleanup_coro is not None:
await cleanup_coro
except (RuntimeError, Exception):
# Event loop might already be closing, ignore the error
pass
async def setup_test_environment(): async def setup_test_environment():
"""Helper function to set up test environment with data, cognify, and triplet embeddings.""" """Helper function to set up test environment with data, cognify, and triplet embeddings."""
# This test runs for multiple db settings, to run this locally set the corresponding db envs # This test runs for multiple db settings, to run this locally set the corresponding db envs