测试规范
后端测试
框架
- pytest — 测试框架
- pytest-asyncio — 异步测试支持
- SQLite — 测试数据库(非 PostgreSQL)
运行测试
cd apps/backend
# 运行所有测试
pytest
# 跳过数据库测试(纯单元测试)
pytest -m no_db
# 运行指定文件
pytest tests/test_auth.py
# 运行指定测试
pytest tests/test_auth.py::test_login
# 带覆盖率
pytest --cov=app --cov-report=html
测试结构
apps/backend/tests/
├── conftest.py # 测试配置和 fixtures
├── test_auth.py # 认证测试
├── test_projects.py # 项目测试
├── test_training.py # 训练任务测试
└── test_services/ # 服务层测试