SuperAPI AI 工具集

pytest

测试与质量

查看项目

更新于 10-16 02:36

技能介绍

用途:该技能面向 Python 的 pytest 测试编写与重构,触发场景为使用 fixture、mocking、parametrize、markers 等模式编写或重构 pytest 测试,也涉及 Prowler 特定的 API/SDK 测试。

主要能力:提供基础测试结构示例,如用类组织测试、用 assert 断言、用 pytest.raises 配合 match 校验异常;fixture 用法,包括返回值 fixture、带 yield 的清理 fixture、scope 为 module/class/session 的 fixture,以及在 conftest.py 中共享 fixture;mocking 用法,基于 unittest.mock 的 patch 与 MagicMock,可设置 return_value、side_effect 并断言调用;parametrize 参数化测试;markers 定义与使用,含 slow、integration 等自定义标记及 skip、skipif;异步测试使用 pytest.mark.asyncio。

使用方式:示例命令包括 pytest、pytest -v、pytest -x、pytest -k "test_user"、pytest -m "not slow"、pytest --cov=src、pytest -n auto、pytest --tb=short。markers 可在 pytest.ini 或 pyproject.toml 的 [tool.pytest.ini_options] 中声明。

适用场景:Python 单元测试与集成测试的编写、重构与运行,尤其是需要 fixture 管理、依赖 mock、参数化用例和标记筛选的项目。

限制:资料未提供安装方式、版本要求、收费信息及具体平台支持;Prowler 相关测试细节需参考 references/prowler-testing.md,官方文档见 https://docs.pytest.org/en/stable/。