27 lines
704 B
Python
27 lines
704 B
Python
import os
|
|
import sys
|
|
import tempfile
|
|
import pytest
|
|
|
|
# 테스트 임시 DB 경로를 import 전에 주입
|
|
_TMP_DB = tempfile.mktemp(suffix=".db")
|
|
os.environ["REALESTATE_DB_PATH"] = _TMP_DB
|
|
|
|
# app 패키지 import 가능하게 PYTHONPATH 보정
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _clean_db():
|
|
"""각 테스트마다 DB 초기화."""
|
|
if os.path.exists(_TMP_DB):
|
|
os.remove(_TMP_DB)
|
|
from app.db import init_db
|
|
init_db()
|
|
yield
|
|
try:
|
|
if os.path.exists(_TMP_DB):
|
|
os.remove(_TMP_DB)
|
|
except OSError:
|
|
pass # Windows: SQLite 파일 잠금 해제 전 삭제 실패 무시
|