0e59936e34
Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
905 B
Python
32 lines
905 B
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
|
monkeypatch.setenv("DATA_DIR", str(tmp_path))
|
|
|
|
from app.config import Settings
|
|
import app.config as config_module
|
|
import app.db as db_module
|
|
import app.main as main_module
|
|
|
|
settings = Settings(_env_file=None, DATA_DIR=tmp_path)
|
|
config_module.settings = settings
|
|
|
|
engine = create_engine(
|
|
settings.db_url,
|
|
connect_args={"check_same_thread": False},
|
|
)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
db_module.engine = engine
|
|
db_module.SessionLocal = SessionLocal
|
|
main_module.engine = engine
|
|
|
|
with TestClient(main_module.app) as test_client:
|
|
yield test_client
|