add logs for tracing processing task
This commit is contained in:
1 parent
efddee217a
commit
073777081e
81 files changed
+25300
-24561
No files matched your search
@@ -1,48 +1,48 @@
|
||||
from typing import AsyncGenerator
|
||||
|
||||
import pytest_asyncio
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
from sqlalchemy.pool import NullPool
|
||||
|
||||
from app.database.session import Base
|
||||
from config import db_settings
|
||||
|
||||
# 테스트 전용 DB URL
|
||||
TEST_DB_URL = db_settings.MYSQL_URL.replace(
|
||||
f"/{db_settings.MYSQL_DB}",
|
||||
"/test_db", # 별도 테스트 DB 사용
|
||||
)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def test_engine():
|
||||
"""각 테스트마다 생성되는 테스트 엔진"""
|
||||
engine = create_async_engine(
|
||||
TEST_DB_URL,
|
||||
poolclass=NullPool, # 테스트에서는 풀 비활성화
|
||||
echo=True, # SQL 쿼리 로깅
|
||||
)
|
||||
|
||||
# 테스트 테이블 생성
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
yield engine
|
||||
|
||||
# 테스트 테이블 삭제
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def db_session(test_engine) -> AsyncGenerator[AsyncSession, None]:
|
||||
"""각 테스트마다 새로운 세션 (격리 보장)"""
|
||||
async_session = async_sessionmaker(
|
||||
test_engine, class_=AsyncSession, expire_on_commit=False
|
||||
)
|
||||
|
||||
async with async_session() as session:
|
||||
yield session
|
||||
await session.rollback() # 테스트 후 롤백
|
||||
from typing import AsyncGenerator
|
||||
|
||||
import pytest_asyncio
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
from sqlalchemy.pool import NullPool
|
||||
|
||||
from app.database.session import Base
|
||||
from config import db_settings
|
||||
|
||||
# 테스트 전용 DB URL
|
||||
TEST_DB_URL = db_settings.MYSQL_URL.replace(
|
||||
f"/{db_settings.MYSQL_DB}",
|
||||
"/test_db", # 별도 테스트 DB 사용
|
||||
)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def test_engine():
|
||||
"""각 테스트마다 생성되는 테스트 엔진"""
|
||||
engine = create_async_engine(
|
||||
TEST_DB_URL,
|
||||
poolclass=NullPool, # 테스트에서는 풀 비활성화
|
||||
echo=True, # SQL 쿼리 로깅
|
||||
)
|
||||
|
||||
# 테스트 테이블 생성
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
yield engine
|
||||
|
||||
# 테스트 테이블 삭제
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def db_session(test_engine) -> AsyncGenerator[AsyncSession, None]:
|
||||
"""각 테스트마다 새로운 세션 (격리 보장)"""
|
||||
async_session = async_sessionmaker(
|
||||
test_engine, class_=AsyncSession, expire_on_commit=False
|
||||
)
|
||||
|
||||
async with async_session() as session:
|
||||
yield session
|
||||
await session.rollback() # 테스트 후 롤백
|
||||
@@ -1,17 +1,17 @@
|
||||
import pytest
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_database_connection(test_engine):
|
||||
"""테스트 엔진을 사용한 연결 테스트"""
|
||||
async with test_engine.begin() as connection:
|
||||
result = await connection.execute(text("SELECT 1"))
|
||||
assert result.scalar() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_usage(db_session):
|
||||
"""세션을 사용한 테스트"""
|
||||
result = await db_session.execute(text("SELECT 1 as num"))
|
||||
assert result.scalar() == 1
|
||||
import pytest
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_database_connection(test_engine):
|
||||
"""테스트 엔진을 사용한 연결 테스트"""
|
||||
async with test_engine.begin() as connection:
|
||||
result = await connection.execute(text("SELECT 1"))
|
||||
assert result.scalar() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_usage(db_session):
|
||||
"""세션을 사용한 테스트"""
|
||||
result = await db_session.execute(text("SELECT 1 as num"))
|
||||
assert result.scalar() == 1
|
||||
+30
-30
@@ -1,30 +1,30 @@
|
||||
import pytest
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.database.session import AsyncSessionLocal, engine
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_database_connection():
|
||||
"""데이터베이스 연결 테스트"""
|
||||
async with engine.begin() as connection:
|
||||
result = await connection.execute(text("SELECT 1"))
|
||||
assert result.scalar() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_creation():
|
||||
"""세션 생성 테스트"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
result = await session.execute(text("SELECT 1"))
|
||||
assert result.scalar() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_database_version():
|
||||
"""MySQL 버전 확인 테스트"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
result = await session.execute(text("SELECT VERSION()"))
|
||||
version = result.scalar()
|
||||
assert version is not None
|
||||
print(f"MySQL Version: {version}")
|
||||
import pytest
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.database.session import AsyncSessionLocal, engine
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_database_connection():
|
||||
"""데이터베이스 연결 테스트"""
|
||||
async with engine.begin() as connection:
|
||||
result = await connection.execute(text("SELECT 1"))
|
||||
assert result.scalar() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_creation():
|
||||
"""세션 생성 테스트"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
result = await session.execute(text("SELECT 1"))
|
||||
assert result.scalar() == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_database_version():
|
||||
"""MySQL 버전 확인 테스트"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
result = await session.execute(text("SELECT VERSION()"))
|
||||
version = result.scalar()
|
||||
assert version is not None
|
||||
print(f"MySQL Version: {version}")
|
||||
Reference in new issue
Block a user