Python Testing
使用 pytest、TDD 方法论、测试夹具(Fixtures)、模拟(Mocking)、参数化(Parametrization)以及覆盖率要求的 Python 测试策略。
Install
/plugin marketplace add xu-xiang/everything-claude-code-zhThe repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.
npx skills add xu-xiang/everything-claude-code-zh --skill python-testinggit clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git /tmp/everything-claude-code-zh
mkdir -p ~/.claude/skills
cp -r /tmp/everything-claude-code-zh/skills/python-testing ~/.claude/skills/python-testingPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Python 测试模式(Python Testing Patterns)
使用 pytest、测试驱动开发(TDD)方法论和最佳实践的 Python 应用程序综合测试策略。
## 何时激活
- 编写新的 Python 代码时(遵循 TDD:红、绿、重构)
- 为 Python 项目设计测试套件时
- 审查 Python 测试覆盖率时
- 搭建测试基础设施时
## 核心测试哲学
### 测试驱动开发 (TDD)
始终遵循 TDD 循环:
1. **红(RED)**:为期望的行为编写一个失败的测试
2. **绿(GREEN)**:编写最少的代码使测试通过
3. **重构(REFACTOR)**:在保持测试通过的同时改进代码
```python
# 步骤 1:编写失败的测试 (红)
def test_add_numbers():
result = add(2, 3)
assert result == 5
# 步骤 2:编写最简实现 (绿)
def add(a, b):
return a + b
# 步骤 3:如果需要则进行重构 (重构)
```
### 覆盖率要求
- **目标**:80% 以上的代码覆盖率
- **关键路径**:要求 100% 覆盖率
- 使用 `pytest --cov` 来衡量覆盖率
```bash
pytest --cov=mypackage --cov-report=term-missing --cov-report=html
```
## pytest 基础
### 基本测试结构
```python
import pytest
def test_addition():
"""测试基本的加法。"""
assert 2 + 2 == 4
def test_string_uppercase():
"""测试字符串转大写。"""
text = "hello"
assert text.upper() == "HELLO"
def test_list_append():
"""测试列表追加。"""
items = [1, 2, 3]
items.append(4)
assert 4 in items
assert len(items) == 4
```
### 断言(Assertions)Details
- Skill name
python-testing- Repository
- xu-xiang/everything-claude-code-zh
- Path
skills/python-testing/SKILL.md- License
- MIT
- Repo updated
- 5 March 2026
FAQ
What does the Python Testing skill do?
使用 pytest、TDD 方法论、测试夹具(Fixtures)、模拟(Mocking)、参数化(Parametrization)以及覆盖率要求的 Python 测试策略。
How do I install the Python Testing skill?
Claude Code plugin: /plugin marketplace add xu-xiang/everything-claude-code-zh. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Python Testing popular?
It lives in xu-xiang/everything-claude-code-zh, which has 2,037 GitHub stars and 332 forks.
Related skills
Backend Patterns
2kxu-xiang/everything-claude-code-zh
Backend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes.
Coding Standards
2kxu-xiang/everything-claude-code-zh
Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.
Frontend Patterns
2kxu-xiang/everything-claude-code-zh
Frontend development patterns for React, Next.js, state management, performance optimization, and UI best practices.
Springboot TDD
2kxu-xiang/everything-claude-code-zh
使用 JUnit 5, Mockito, MockMvc, Testcontainers 和 JaCoCo 进行 Spring Boot 的测试驱动开发(TDD)。适用于添加新功能、修复 bug 或重构场景。
Python Testing
2kxu-xiang/everything-claude-code-zh
使用 pytest、TDD 方法论、固件(Fixtures)、模拟(Mocking)、参数化及覆盖率要求的 Python 测试策略。
Springboot TDD
2kxu-xiang/everything-claude-code-zh
使用JUnit 5、Mockito、MockMvc、Testcontainers和JaCoCo进行Spring Boot的测试驱动开发。适用于添加功能、修复错误或重构时。
Browse the most popular Claude skills, all testing & qa skills, or write your own with the skills generator.