用途:在编写 Python 测试、创建测试文件或测试目录、配置 pytest、使用测试夹具(fixture)或 mock、运行测试并检查覆盖率时启用该技能。
主要能力:提供 pytest 常用命令,包括运行全部测试 uv run pytest、运行指定文件 uv run pytest tests/test_auth.py、覆盖率 uv run pytest --cov=src --cov-report=html、详细输出 uv run pytest -v -s、按模式匹配 uv run pytest -k "test_user"、仅运行上次失败 uv run pytest --lf。测试结构采用 Arrange-Act-Assert(AAA)模式。目录结构示例将共享夹具放在 tests/conftest.py,并按 unit、integration、e2e 分层。支持 fixture(如 app、client、sample_user)、参数化测试、mock(Mock、patch)、异常断言(pytest.raises)、临时文件测试(tmp_path)、环境变量测试(monkeypatch)。覆盖率可在 pyproject.toml 中通过 [tool.pytest.ini_options] 与 [tool.coverage.run] 配置,testpaths、addopts 等。命名约定:测试文件 test_.py、测试函数 test_、测试类 Test*。
限制:资料未提供版本要求、安装方式、支持平台、收费情况与效果保证;异步测试、集成测试示例、CI/CD 集成与测试优先级指南仅指向 AgentUsage/testing_python.md,本页未展开。