test(fixtures): add testcontainers Postgres fixture for Stage 0
新建 backend/tests/fixtures/postgres.py,提供两层 fixture:
- postgres_container (session 级):用 PostgresContainer 起 postgres:16-alpine
- postgres_url (function 级):每 test 一个 ephemeral DB,teardown 时
pg_terminate_backend 清掉残连后 DROP DATABASE
为什么 per-DB 而不是 per-schema:asyncpg + SQLAlchemy 不通过 URL 传 search_path,
per-DB 一次 ~50ms 开销可接受,让 test 代码不感知 schema。
Docker 不可用时 fixture 自动 pytest.skip 而非 error,dev 环境无 Docker
仍能跑其余 3086 个测试。
注册 pytest mark `postgres`、把 tests/ 加 sys.path 让 pytest_plugins
按 `fixtures.postgres` 路径解析(不加 tests/__init__.py 避免干扰
现有 pytest 发现行为)。
Stage 0 PR1 T1.3.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,13 @@ import pytest
|
||||
# Make 'app' and 'deerflow' importable from any working directory
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "scripts"))
|
||||
# Make 'fixtures.*' importable as plugin modules from this conftest.
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
# Register fixture plugin modules so tests can request fixtures by name
|
||||
# without ad-hoc imports. ``fixtures.postgres`` provides
|
||||
# ``postgres_container`` (session-scoped) and ``postgres_url`` (per-test).
|
||||
pytest_plugins = ["fixtures.postgres"]
|
||||
|
||||
# Break the circular import chain that exists in production code:
|
||||
# deerflow.subagents.__init__
|
||||
|
||||
Reference in New Issue
Block a user