SuperAPI AI 工具集

pytest

测试与质量

查看项目

更新于 10-16 04:35

技能介绍

用途:为编写或重构 pytest 测试提供模式参考,涵盖 fixture、mock、parametrize、marker 等主题,并指向 Prowler 特定的 API/SDK 测试资料。

主要能力:展示基础测试结构(类与断言、pytest.raises 异常匹配);fixture 的定义、依赖注入、yield 清理与 scope(module/class/session),以及 conftest.py 共享 fixture;使用 unittest.mock 的 patch 与 MagicMock 进行打桩和断言调用;parametrize 参数化用例;自定义 marker 及 skip/skipif;pytest.mark.asyncio 异步测试。

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

适用场景:Python 单元测试与集成测试的编写与重构,需要 fixture 复用、外部依赖打桩、参数化覆盖或按 marker 筛选测试时。

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