← 返回 Skills 市场
shenghoo123-png

Pytest Test Master

作者 shenghoo123-png · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
118
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install pytest-test-master
功能描述
掌握 pytest fixtures 范围、参数化、mock 用法及 coverage 报告,提升测试结构清晰度和覆盖率分析能力。
使用说明 (SKILL.md)

pytest-test-master — pytest 专项技能

痛点

  • 会写测试,但 fixtures 用得乱,setup/teardown 纠缠不清
  • 不知道什么时候用 scope、params、yield_fixture
  • mock/patch 混用,容易写错 target 路径导致假通过
  • conftest.py 越写越乱,跨文件 fixtures 共享搞不清
  • parametrize 只会简单列表,多维度组合测试不知怎么写
  • coverage 跑出来了但不知道怎么看报告找盲区
  • 测试数据靠手写 hardcode,faker 和 factory_boy 不知道哪个场景用

场景

  • 接手老项目,看到 conftest.py 里有 200 行不知道从哪入手
  • 想用 pytest-mock 替代 unittest.mock 但不确定哪个更合适
  • 需要参数化测试覆盖 10 种边界组合,手动写 10 个 test 函数太累
  • 新人入职,问你 fixture scope 怎么选,autouse 什么时候开
  • 想知道 coverage 怎么配合 CI,threshold 怎么设才合理
  • 想快速生成真实感测试数据而不是 all() equal 1

定价

  • Free:fixtures 基础用法 + mock/patch 入门(单文件示例)
  • Pro 19元:conftest 进阶 + parametrize 组合 + pytest-cov 报告解读 + faker 集成
  • Team 49元:factory_boy 高级模式 + CI/CD coverage gate + 全量示例模板 + 技术支持

指令格式

子命令

pytest-test-master fixtures [topic]    # fixtures 最佳实践
pytest-test-master mock [topic]         # mock/patch 使用模式
pytest-test-master parametrize [topic]  # 参数化测试
pytest-test-master coverage [topic]     # coverage 报告分析
pytest-test-master data [topic]         # 测试数据生成
pytest-test-master --list               # 列出所有可用主题
pytest-test-master --all                # 输出完整指南(Pro/Team)

fixtures 子主题

pytest-test-master fixtures scope       # function/class/module/session 区别
pytest-test-master fixtures yield        # yield_fixture vs setup
pytest-test-master fixtures params       # 参数化 fixture
pytest-test-master fixtures autouse     # autouse 自动执行
pytest-test-master fixtures request      # request.fixture_registry
pytest-test-master fixtures teardown     # yield vs addfinalizer
pytest-test-master fixtures session      # session-scope 跨文件共享
pytest-test-master fixtures inject       # 依赖注入模式

mock 子主题

pytest-test-master mock patch            # @patch 装饰器用法
pytest-test-master mock mock_obj         # MagicMock/PropertyMock
pytest-test-master mock assert           # 断言调用次数和参数
pytest-test-master mock freeze           # freeze_time 时间冻结
pytest-test-master mock spy              # Spy 模式保留真实行为
pytest-test-master mock scope            # session/class/function mock scope
pytest-test-master mock common          # 常见错误和修复

parametrize 子主题

pytest-test-master parametrize basic     # @pytest.mark.parametrize
pytest-test-master parametrize ids       # 自定义测试 ID
pytest-test-master parametrize indirect  # 间接参数化
pytest-test-master parametrize combine   # 多个 parametrize 组合
pytest-test-master parametrize generate  # 动态生成参数
pytest-test-master parametrize product  # 笛卡尔积组合

coverage 子主题

pytest-test-master coverage report      # coverage report 阅读
pytest-test-master coverage html        # HTML 报告生成
pytest-test-master coverage xml         # CI 集成 XML 报告
pytest-test-master coverage threshold  # 阈值设置
pytest-test-master coverage combine    # 多文件合并覆盖
pytest-test-master coverage exclude    # 排除文件和行
pytest-test-master coverage debug      # 调试覆盖问题

data 子主题

pytest-test-master data faker          # Faker.py 用法
pytest-test-master data factory         # factory_boy 工厂模式
pytest-test-master data fixture         # fixture 中集成数据生成
pytest-test-master data fixture         # @pytest.fixture 结合 faker
pytest-test-master data seed           # 固定种子复现数据
pytest-test-master data strategy       # 不同数据策略

Free 内容示例(fixtures scope)

# fixture scope 四种级别
import pytest

# function(默认):每个测试函数前后执行
@pytest.fixture
def db_connection():
    conn = create_connection()
    yield conn  # yield 前 = setup,yield 后 = teardown
    conn.close()

# class:类的所有测试方法共享同一个实例
@pytest.fixture(scope="class")
def test_client():
    client = FlaskClient()
    client.connect()
    yield client
    client.disconnect()

# module:一个模块只执行一次
@pytest.fixture(scope="module")
def django_db_setup():
    # 模块级别 setup
    pass

# session:整个测试 session 只执行一次
@pytest.fixture(scope="session")
def base_url():
    return "https://api.example.com"

Free 内容示例(mock patch)

# @patch 装饰器:mock 外部依赖
from unittest.mock import patch

@patch("myapp.service.requests.get")
def test_fetch_user(mock_get):
    mock_get.return_value = Mock(status_code=200, json=lambda: {"name": "Alice"})
    result = fetch_user(1)
    assert result["name"] == "Alice"
    # mock_get.assert_called_once()  # 可选断言

输出格式

每个子命令输出:

  1. 概念说明(何时用)
  2. 代码示例(拿来即用)
  3. 常见错误(避坑指南)
  4. 进阶技巧(Pro/Team 内容会注明)

与 test-master 的互补关系

  • test-master:测试数据生成(输入)
  • pytest-test-master:pytest 编写技巧(过程)
  • 两者配合:生成数据 → 编写测试 → 覆盖报告
安全使用建议
This skill is a self-contained pytest tutorial/CLI with example code and unit tests, and it does not ask for secrets or perform network downloads. Things to consider before installing or running: 1) Running setup.sh will execute pytest on the included test suite and run the CLI examples — run in an isolated environment (virtualenv/container) if you prefer. 2) The README/usage expects pytest to be present; install pytest via pip before running tests. 3) The package includes doc examples that reference external resources (databases, Selenium) only as examples — those are not contacted automatically, but if you adapt examples, be careful to not point them at production services. 4) The repository advertises paid 'Pro/Team' tiers in docs but contains only local content; payment or remote services are not implemented here. Overall it appears coherent and low-risk, but as with any code you should review and run it in an isolated environment if you have security concerns.
能力评估
Purpose & Capability
Name/description (pytest fixtures, mock, parametrize, coverage, data) match the included files (cli.py, pytest_master.py, README, examples and tests). The files primarily contain static documentation and example snippets appropriate for a teaching/reference skill.
Instruction Scope
SKILL.md instructs only local CLI usage and shows example code. The provided setup.sh runs pytest/tests and demo CLI commands — running those will execute the repository's Python code and unit tests (expected for this package). Note: the skill does not attempt to read arbitrary user files, environment secrets, or call external endpoints in its code; examples reference services (databases, selenium) only in doc strings and are not executed by default.
Install Mechanism
No install spec or external downloads are declared. All code is included in the package. There are no URLs, archive extracts, or remote installers. The README suggests installing pytest via pip, which is normal for running tests/examples.
Credentials
The skill requests no environment variables or credentials. It implicitly expects Python and pytest to be available to run the tests and CLI (README instructs pip install pytest). This runtime dependency is reasonable but not declared as 'required env/binaries' in the registry metadata — a minor documentation gap, not malicious.
Persistence & Privilege
always:false and no installation script that modifies agent/system-wide configuration. The skill will not auto-enable itself; it contains only a local CLI and library. Autonomous invocation by an agent is allowed (default) but there are no elevated privileges requested.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install pytest-test-master
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /pytest-test-master 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
pytest-test-master 1.0.0 — Initial Release - Provides organized best practices for pytest: fixtures, mocking, parameterization, coverage, and test data generation. - Includes pain point analysis and actionable solutions for common pytest usage issues. - Offers free and paid (Pro/Team) content tiers with clear command and topic structures. - Supplies detailed subcommands for each area, with expected output format: concept, code, error pitfalls, and advanced tips. - Designed as a hands-on tool to complement test-master by focusing on the “writing tests” process with practical guides and examples.
元数据
Slug pytest-test-master
版本 1.0.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

Pytest Test Master 是什么?

掌握 pytest fixtures 范围、参数化、mock 用法及 coverage 报告,提升测试结构清晰度和覆盖率分析能力。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 118 次。

如何安装 Pytest Test Master?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install pytest-test-master」即可一键安装,无需额外配置。

Pytest Test Master 是免费的吗?

是的,Pytest Test Master 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Pytest Test Master 支持哪些平台?

Pytest Test Master 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Pytest Test Master?

由 shenghoo123-png(@shenghoo123-png)开发并维护,当前版本 v1.0.0。

💬 留言讨论