py-test-creator:自动生成 pytest 模板 - Openclaw Skills
作者:互联网
2026-04-17
什么是 py-test-creator?
py-test-creator 是 Openclaw Skills 生态系统中的一个专门扩展,旨在自动化繁琐的单元测试编写过程。通过对 Python 源代码进行静态分析,此技能可以识别函数签名、类型提示和文档字符串,从而构建完整的测试框架。它本质上是开发与质量保证之间的桥梁,确保你编写的每个函数都配有一套强大的测试用例,而无需手动编写样板代码。
此技能专为优先考虑代码可靠性但希望加快开发速度的开发人员而设计。它不仅仅是创建空文件;它还合成了有意义的测试脚手架,包括正确的导入、fixture 设置和断言结构。无论你是在处理小型脚本还是大型库,Openclaw Skills 中的 py-test-creator 都能确保你的测试套件保持一致且全面。
下载入口:https://github.com/openclaw/skills/tree/main/skills/martinforsulu/neo-py-test-creator
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install neo-py-test-creator
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 neo-py-test-creator。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
py-test-creator 应用场景
- 在初始开发阶段为新的 Python 模块快速生成测试文件。
- 确保具有多个参数组合和类型提示的复杂函数的边缘情况覆盖。
- 通过利用通用的 Openclaw Skills 自动化功能,在团队中标准化单元测试格式。
- 将现有的函数文档和文档字符串转换为可操作的测试方法描述。
- 在为类方法设置 pytest fixture 时,减少手动样板代码的时间开销。
- 用户通过 Openclaw Skills 支持的自然语言界面向代理提供 Python 文件路径或原始代码片段。
- 该技能利用内部 AST(抽象语法树)解析器分析 Python 代码结构,提取方法、参数和元数据。
- 生成引擎将这些签名映射到兼容 pytest 的模板,自动包含边界检查和无效类型检查。
- 创建相应的测试文件(例如 test_module.py),并包含所有必要的 import 语句和测试 fixture。
- 最终输出呈现给用户,提供一个现成的、可与标准 Python 测试工作流完美集成的测试套件。
py-test-creator 配置指南
要将此工具集成到你的 Openclaw Skills 工作流中,你需要安装通过提供的包定义管理的依赖项。在终端中运行以下命令:
npm install
此过程将设置所需的 Node.js 环境以及代码解析和测试生成所需的基于 Python 的 AST 实用程序。
py-test-creator 数据架构与分类体系
该技能遵循结构化的输入/输出模型,以保持项目目录的一致性:
| 组件 | 类型 | 描述 |
|---|---|---|
| 输入源 | .py 文件 | 包含待测试函数或类的目标 Python 脚本。 |
| 输出文件 | .py 文件 | 一个以 test_ 为前缀的新文件,包含生成的 pytest 代码。 |
| AST 元数据 | 内部 | 提取的函数名称、类型提示和文档字符串,用于填充测试逻辑。 |
| 逻辑映射 | 模板 | Python 类型到常见测试边缘情况(例如 None、空字符串、大整数)的映射。 |
name: py-test-creator
description: Automatically generates pytest-compatible unit test templates from Python function signatures and docstrings
py-test-creator — Skill Documentation
Overview
py-test-creator is an OpenClaw skill that automatically generates comprehensive pytest unit test templates from Python code. It parses function signatures, type hints, and docstrings to create actionable test scaffolding that covers edge cases and parameter combinations.
Key features:
- Parse Python functions with complex signatures (defaults, type hints, variadic args)
- Generate pytest-compatible test methods with proper assertions
- Handle both standalone functions and class methods
- Convert docstrings into test method documentation
- Create ready-to-use test files with correct imports and structure
Installation
Dependencies are managed via package.json. Install with:
npm install
This will install the required Python packages (pytest, ast-parser utilities) and Node.js dependencies for the skill runner.
Usage
Trigger the skill with natural language:
- "Create unit tests for this Python function"
- "Generate test templates from these function signatures"
- "Write pytest tests for my Python methods"
- "Create unit test scaffolding from docstrings"
The skill expects a Python file or code snippet as input and produces a corresponding test file.
Input/Output
Input:
A Python file path or raw code containing one or more functions/methods.
Output:
A test file (e.g., test_) containing pytest test functions with:
import pyteststatements- Test fixtures for common parameter types
- Edge case coverage (None values, boundaries, invalid types)
- Parametrized tests where appropriate
- Docstrings explaining test purpose
Example:
Input (utils.py):
def add(a: int, b: int) -> int:
"""Add two integers and return the result."""
return a + b
Output (test_utils.py):
import pytest
from utils import add
def test_add_basic_integers():
"""Test add function with basic positive integers."""
assert add(1, 2) == 3
def test_add_negative_numbers():
"""Test add function with negative integers."""
assert add(-1, -2) == -3
def test_add_zero():
"""Test add function with zero."""
assert add(0, 5) == 5
assert add(5, 0) == 5
def test_add_large_numbers():
"""Test add function with large integers."""
assert add(1000000, 2000000) == 3000000
Configuration
No configuration required. The skill uses default pytest conventions.
Optional environment variables:
PYTEST_STRICT: Set totrueto enable strict mark handlingTEST_COVERAGE: Set totrueto include coverage hints in generated tests
Error Handling
The skill exits with non-zero status on:
- Invalid Python syntax
- Missing input file/code
- Permission errors writing output
- AST parsing failures
Error messages are logged to stderr.
Limitations
Out of scope:
- Running or validating generated tests
- Integration/end-to-end testing
- Multi-language support (Python only)
- CI/CD integration
- Performance optimization of tests
Files
The skill package includes:
skill/
├── SKILL.md # This documentation
├── package.json # NPM package definition
├── README.md # Quick start guide
└── scripts/
├── main.py # CLI entry point
├── parser.py # Python AST parser
├── generator.py # Test template generator
└── cli.py # Command-line interface
Resources
- pytest Documentation
- Python AST Module
- OpenClaw Skill System
Support
For issues, feature requests, or contributions, visit:
- Repository:
openclaw/openclaw - Discord: https://discord.com/invite/clawd
License
MIT ? OpenClaw Contributors
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
DuckDuckGo 搜索:为 AI 提供即时网络访问 - Openclaw Skills
SynapseAI Wallet:AI 智能体托管支付 - Openclaw Skills
OSINT 图谱分析器:知识图谱与模式发现 - Openclaw Skills
Agent Relay Digest:精选 AI Agent 社区摘要 - Openclaw Skills
Pinterest API v5:自动化 Pin 和看板管理 - Openclaw Skills
FACEPALM:智能日志分析与聊天故障排除 - Openclaw 技能
clawback: 安全的 Gmail 代理与策略执行 - Openclaw Skills
Didit 身份验证:全球身份证件 OCR - Openclaw Skills
OpenClaw Git: 自动化工作区同步与备份 - Openclaw Skills
个人分析:AI 对话洞察与生产力 - Openclaw Skills
AI精选
