"""Shared fixtures. Tests run against a throwaway database per test.""" from __future__ import annotations import os import sys from pathlib import Path import pytest sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) class FakeRequest: """Minimal stand-in for starlette's Request: routers only read the editor header.""" def __init__(self, actor: str = "测试员") -> None: self.headers = {"X-Editor": actor} @pytest.fixture() def db(tmp_path, monkeypatch): monkeypatch.setenv("DB_PATH", str(tmp_path / "test.db")) from app import config monkeypatch.setattr(config, "db_path", lambda: tmp_path / "test.db") from app.db import connect, init_db from app.seed import seed init_db() conn = connect() seed(conn) yield conn conn.close() @pytest.fixture() def request_(): return FakeRequest()