用途:该技能面向 Semantic Link Labs 项目,指导开发者使用 pytest 在本地运行测试,以验证代码改动、调试失败用例并在提交前完成检查。
主要能力:覆盖运行全部测试、按文件或名称模式筛选测试、显示详细输出与打印语句、查看耗时、遇错即停、进入调试器、显示局部变量等常见 pytest 用法,并说明测试发现规则(test_.py、test.py、test* 函数、Test* 类)。
使用方式:先安装开发依赖,可执行 pip install -e ".[test]";也可用 conda env create -f environment.yml、conda activate fabric、pip install -e . 创建环境。常用命令包括 pytest -s tests/、pytest -sv tests/、pytest -s tests/test_example.py、pytest -s tests/ -k test_my_function、pytest -sx tests/、pytest --durations=10 tests/、pytest --pdb tests/、pytest -l tests/。测试位于 tests/ 目录,配置在 pyproject.toml。CI 使用 GitHub Actions,工作流为 .github/workflows/build.yaml,其中执行 pytest -s tests/。
适用场景:本地验证改动、按名称运行特定测试、排查导入或依赖缺失问题、提交前回归检查。
限制:资料未提供测试覆盖率、性能基准、支持平台或版本要求等信息;遇到导入错误可确认以可编辑模式安装包,缺少依赖可安装 test 依赖,环境异常可重建 conda 环境。