import os from pathlib import Path # 测试环境:允许无密码启动,避免模块级 create_app() 因 fail-secure 抛错。 os.environ.setdefault("PPM_ALLOW_NO_AUTH", "1") import pytest from fastapi.testclient import TestClient from app.auth import SessionManager, make_password_hash from app.main import create_app @pytest.fixture() def client(tmp_path: Path): app = create_app(tmp_path / "data", Path(__file__).parents[1] / "config" / "layouts", SessionManager(None)) with TestClient(app) as test_client: yield test_client @pytest.fixture() def auth_client(tmp_path: Path): manager = SessionManager(make_password_hash("secret")) app = create_app(tmp_path / "data", Path(__file__).parents[1] / "config" / "layouts", manager) with TestClient(app) as test_client: yield test_client