import os import sys import tempfile from pathlib import Path import pytest from fastapi.testclient import TestClient TEST_DB_PATH = Path(tempfile.gettempdir()) / "server_panel_test.db" os.environ["DATABASE_URL"] = f"sqlite:///{TEST_DB_PATH.as_posix()}" os.environ["ACTION_EXECUTION_MODE"] = "worker" os.environ["TELEGRAM_BOT_API_SECRET"] = "test-bot-secret" BACKEND_DIR = Path(__file__).resolve().parents[1] if str(BACKEND_DIR) not in sys.path: sys.path.insert(0, str(BACKEND_DIR)) from app.db.session import Base, engine # noqa: E402 from app.main import app # noqa: E402 @pytest.fixture(autouse=True) def reset_database(): Base.metadata.drop_all(bind=engine) Base.metadata.create_all(bind=engine) yield Base.metadata.drop_all(bind=engine) @pytest.fixture def client(): with TestClient(app) as test_client: yield test_client