单元测试指南
📋 目录
🔧 安装测试依赖
安装测试依赖
pip install -e ".[test]"
pip install pytest pytest-asyncio pytest-cov pytest-mock coverage freezegun
🏃 本地运行测试
运行所有测试
pytest
pytest tests/
运行特定测试文件
pytest tests/unit_tests/test_config.py
pytest tests/unit_tests/
运行特定测试用例
pytest tests/unit_tests/test_config.py::TestResolveEnvVars::test_resolve_string_with_env_var
pytest tests/unit_tests/test_config.py::TestResolveEnvVars
常用测试选项
pytest -v
pytest -s
pytest --tb=long
pytest --lf
pytest -x
pytest -n auto
运行带标记的测试
pytest -m unit
pytest -m integration
pytest -m slow
pytest -m "not slow"
📊 测试覆盖率
生成覆盖率报告
pytest --cov=jiuwenswarm --cov-report=term-missing
pytest --cov=jiuwenswarm --cov-report=html
pytest --cov=jiuwenswarm --cov-report=xml
查看覆盖率报告
pytest --cov=jiuwenswarm --cov-report=html
open htmlcov/index.html
xdg-open htmlcov/index.html