test: pytest 工程化落地 — 本地门禁、容器测试镜像、迁移链冒烟测试

- 门禁: 本地 pre-push 钩子(.git/hooks,推送前强制跑全量 pytest)
- Docker: 新增 test 镜像阶段(含 dev 依赖与 tests),compose 提供
  --profile test run --rm test 入口;dev.sh 支持 ./dev.sh test
- 测试基建: 根目录 conftest.py 统一 DATABASE_URL/APP_ENCRYPTION_KEY,
  移除 9 个测试文件内的重复 setdefault(含多余 import os)
- 迁移冒烟: tests/test_migrations.py 校验链线性、脚本可编译、空库整链
  upgrade head 后与 Base.metadata 表/列/索引对齐
- 修复冒烟测试发现的漂移: YybRechargeTask.task_id 冗余 index=True
  (唯一索引已覆盖,迁移链未建普通索引,模型与真实 schema 对齐)
- alembic.ini: path_separator=os 消除弃用告警;README 补测试章节
This commit is contained in:
yml2213
2026-08-30 18:54:00 +08:00
parent 9497e1ace6
commit 3ce1c7a51b
17 changed files with 193 additions and 34 deletions
+15
View File
@@ -99,3 +99,18 @@ HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
# 同一容器内启动 Web 与本机 Worker;入口脚本负责联动退出和信号转发。
ENTRYPOINT ["/app/docker-entrypoint.sh"]
# ===== 阶段4: 测试镜像(含 dev 依赖与测试代码,可容器内跑 pytest)=====
# 用法: docker compose --profile test run --rm test
FROM runtime AS test
ARG USE_CHINA_MIRRORS=true
COPY tests/ ./tests/
COPY conftest.py ./
RUN if [ "$USE_CHINA_MIRRORS" = "true" ]; then \
(UV_INDEX_URL=https://mirrors.cloud.aliyuncs.com/pypi/simple/ uv sync --frozen --group dev || \
UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ uv sync --frozen --group dev || \
uv sync --frozen --group dev); \
else \
uv sync --frozen --group dev; \
fi