SuperAPI AI 工具集

python-testing

编程与开发

查看项目

更新于 10-15 23:41

技能介绍

用途:为 Python 项目编写与维护测试,核心以 pytest 为标准工具,并整合覆盖率、Mock、异步与属性测试等配套方案。

主要能力:pytest 基础测试结构与断言(含 pytest.raises、pytest.approx);fixture 及 function/class/module/session 作用域、参数化 fixture;@pytest.mark.parametrize 参数化测试与组合用例;使用 pytest-mock 的 mocker.patch、return_value、side_effect 及上下文管理器/类 Mock;pytest-asyncio 异步测试与异步 fixture;面向 FastAPI 的 ASGITransport + AsyncClient 测试;通过 pytest-cov 生成覆盖率报告并设阈值;自定义 marker(slow、integration 等);Hypothesis 属性测试与 syrupy 快照测试;测试目录与 conftest 层级组织。

使用方式:安装示例为 uv add --dev pytest pytest-cov pytest-asyncio pytest-xdist 或 pip install pytest pytest-cov pytest-asyncio pytest-xdist。常用命令:pytest、pytest -v、pytest -k "name"、pytest -x、pytest --lf、pytest -n auto;覆盖率 pytest --cov=src --cov-report=html。配置写入 pyproject.toml 的 [tool.pytest.ini_options] 等段落。测试文件建议置于 tests/ 下,按 unit/integration/e2e 分层。

适用场景:单元测试、集成测试、端到端测试、异步与 Web API 测试、需要 Mock 外部依赖或数据库的场景。

限制:资料未提供该技能的安装与激活步骤、许可、收费与价格、支持的 Python 版本范围、性能数据及官方维护状态,这些暂未提供。