← Back to Skills Marketplace
pytest-test-master
by
shenghoo123-png
· GitHub ↗
· v1.0.0
· MIT-0
122
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install pytest-test-master-kay
Description
提供 pytest fixtures 用法、mock/patch 操作、参数化测试、coverage 报告解读和测试数据生成的专项指导和示例。
README (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() # 可选断言
输出格式
每个子命令输出:
- 概念说明(何时用)
- 代码示例(拿来即用)
- 常见错误(避坑指南)
- 进阶技巧(Pro/Team 内容会注明)
与 test-master 的互补关系
- test-master:测试数据生成(输入)
- pytest-test-master:pytest 编写技巧(过程)
- 两者配合:生成数据 → 编写测试 → 覆盖报告
Usage Guidance
总体上这是一个本地离线的 pytest 教学/示例包,内部内容与描述一致。注意几点:1) setup.sh 会在本地运行 pytest tests/ 并调用 cli.py,若在不受信任环境或与真实项目同一环境运行,请先在隔离的虚拟环境或容器中执行;2) 文档示例中引用了 selenium、数据库连接等外部资源,但这些为示例文本/代码片段,通常不会在正常使用下触发网络或访问凭据;3) SKILL.md 中的 Pro/Team 定价看起来是营销说明,代码仓内并未强制付款机制;4) 若你打算把该技能用在含敏感数据的 CI 环境,先检查并在沙箱内运行 tests/ 以确认没有意外的外部调用。基于当前源代码和说明,我认为此技能内部一致且风险低。
Capability Analysis
Type: OpenClaw Skill
Name: pytest-test-master-kay
Version: 1.0.0
The skill bundle is an educational tool and CLI utility designed to provide best practices, code examples, and documentation for the Python testing framework 'pytest'. Analysis of the core logic in 'pytest_master.py' and the interface in 'cli.py' shows it only serves static content from internal dictionaries; it does not perform network requests, access sensitive files, or execute untrusted code. The 'setup.sh' script and unit tests in 'tests/test_pytest_master.py' are standard for development and lack any malicious indicators or exfiltration patterns.
Capability Assessment
Purpose & Capability
技能名与描述(pytest fixtures、mock、parametrize、coverage、测试数据)与仓内文件一致:包含 CLI、核心内容库(文本示例)、示例/测试和一个演示安装脚本。没有请求与描述不符的云凭据、外部 API key 或非相关二进制。
Instruction Scope
SKILL.md 的运行说明只要求本地运行 cli.py、阅读/输出示例、以及可选择执行 setup.sh(运行本地 pytest tests/ 并打印示例)。文档和代码示例中偶有对 selenium、数据库等库的引用,但这些都以示例文本形式存在,且没有自动去读取或上传主机上敏感文件或环境变量。
Install Mechanism
没有声明的 install spec(instruction-only 风格)且仓库仅包含本地脚本/文档。没有从不明 URL 下载或解压可执行代码的行为,因此安装机制风险低。
Credentials
不要求任何环境变量、凭据或配置路径。SKILL.md 和代码不会读取未声明的凭据或敏感配置。示例中提到的外部连接字符串(postgresql://...)是示例占位符,不是技能运行所需的真实凭据。
Persistence & Privilege
flags 中没有 always:true,也不会修改其他技能或系统范围配置。默认允许模型调用(平台默认),但该技能本身无长期驻留或自我启用逻辑。
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install pytest-test-master-kay - After installation, invoke the skill by name or use
/pytest-test-master-kay - Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release
Metadata
Frequently Asked Questions
What is pytest-test-master?
提供 pytest fixtures 用法、mock/patch 操作、参数化测试、coverage 报告解读和测试数据生成的专项指导和示例。 It is an AI Agent Skill for Claude Code / OpenClaw, with 122 downloads so far.
How do I install pytest-test-master?
Run "/install pytest-test-master-kay" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is pytest-test-master free?
Yes, pytest-test-master is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does pytest-test-master support?
pytest-test-master is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created pytest-test-master?
It is built and maintained by shenghoo123-png (@shenghoo123-png); the current version is v1.0.0.
More Skills