Spaces:
Sleeping
Sleeping
File size: 1,397 Bytes
41aafc4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | """
Pytest configuration and fixtures for SCM microservice tests.
"""
import pytest
import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
import redis.asyncio as redis
from app.core.config import settings
# Test database and cache names
TEST_DB_NAME = "scm_test_db"
TEST_REDIS_DB = 15
@pytest.fixture(scope="session")
def event_loop():
"""Create an event loop for the test session"""
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
@pytest.fixture(scope="function")
async def test_db():
"""
Provide a clean test database for each test.
Drops the database after the test completes.
"""
client = AsyncIOMotorClient(settings.MONGODB_URI)
db = client[TEST_DB_NAME]
yield db
# Cleanup: drop the test database
await client.drop_database(TEST_DB_NAME)
client.close()
@pytest.fixture(scope="function")
async def test_redis():
"""
Provide a clean Redis instance for each test.
Flushes the test database after the test completes.
"""
redis_client = redis.Redis(
host=settings.REDIS_HOST,
port=settings.REDIS_PORT,
password=settings.REDIS_PASSWORD,
db=TEST_REDIS_DB,
decode_responses=True
)
yield redis_client
# Cleanup: flush the test database
await redis_client.flushdb()
await redis_client.close()
|