Files
dodo/tests/conftest.py
bboysoul 6c234d7d82
ci / gitleaks (push) Successful in 1m19s
ci / docker (push) Successful in 5m48s
feat: strengthen backup and mobile workflows
2026-09-16 21:12:52 +08:00

31 lines
870 B
Python

import asyncio
import os
from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import event
@pytest.fixture
def client(tmp_path: Path):
os.environ["DODO_DATABASE_URL"] = f"sqlite+aiosqlite:///{tmp_path / 'test.db'}"
os.environ["DODO_AUTO_CREATE_SCHEMA"] = "true"
from backend.config import get_settings
get_settings.cache_clear()
from backend.db import get_engine, reset_engine
reset_engine()
engine = get_engine()
@event.listens_for(engine.sync_engine, "connect")
def enable_sqlite_foreign_keys(dbapi_connection, _):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
from backend.main import app
with TestClient(app) as test_client:
yield test_client
asyncio.run(engine.dispose())
reset_engine()