55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
# ================================================================
|
|
# services/forecasting/tests/conftest.py
|
|
# ================================================================
|
|
"""
|
|
Test configuration and fixtures for forecasting service
|
|
"""
|
|
|
|
import pytest
|
|
import asyncio
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
from app.core.config import settings
|
|
from shared.database.base import Base
|
|
|
|
# Test database URL
|
|
TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
|
|
|
|
@pytest.fixture(scope="session")
|
|
def event_loop():
|
|
"""Create an instance of the default event loop for the test session."""
|
|
loop = asyncio.get_event_loop_policy().new_event_loop()
|
|
yield loop
|
|
loop.close()
|
|
|
|
@pytest.fixture
|
|
async def test_db():
|
|
"""Create test database session"""
|
|
|
|
# Create test engine
|
|
engine = create_async_engine(
|
|
TEST_DATABASE_URL,
|
|
poolclass=StaticPool,
|
|
connect_args={"check_same_thread": False},
|
|
echo=False
|
|
)
|
|
|
|
# Create tables
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
|
|
# Create session factory
|
|
TestSessionLocal = async_sessionmaker(
|
|
engine,
|
|
class_=AsyncSession,
|
|
expire_on_commit=False
|
|
)
|
|
|
|
# Provide session
|
|
async with TestSessionLocal() as session:
|
|
yield session
|
|
|
|
# Cleanup
|
|
await engine.dispose()
|