Python Testing

使用 pytest、TDD 方法论、固件(Fixtures)、模拟(Mocking)、参数化及覆盖率要求的 Python 测试策略。

2,037 stars 332 forksTesting & QA Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add xu-xiang/everything-claude-code-zh

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add xu-xiang/everything-claude-code-zh --skill python-testing
Manual install
git 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/docs/ja-JP/skills/python-testing ~/.claude/skills/python-testing

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Python 测试模式

使用 pytest、TDD 方法论和最佳实践的 Python 应用程序全面测试策略。

## 何时启用

- 编写新的 Python 代码时(遵循 TDD:红、绿、重构)
- 设计 Python 项目的测试套件时
- 审查 Python 测试覆盖率时
- 搭建测试基础设施时

## 核心测试哲学

### 测试驱动开发 (TDD)

始终遵循 TDD 循环。

1. **红 (RED)**: 编写针对预期行为的失败测试
2. **绿 (GREEN)**: 编写使测试通过的最少代码
3. **重构 (REFACTOR)**: 在保持测试通过的同时改进代码

```python
# 步骤 1: 编写失败的测试 (RED)
def test_add_numbers():
    result = add(2, 3)
    assert result == 5

# 步骤 2: 编写最简单的实现 (GREEN)
def add(a, b):
    return a + b

# 步骤 3: 必要时进行重构 (REFACTOR)
```

### 覆盖率要求

- **目标**: 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)
Read the full skill on GitHub

Details

Skill name
python-testing
Path
docs/ja-JP/skills/python-testing/SKILL.md
License
MIT
Repo updated
5 March 2026

FAQ

What does the Python Testing skill do?

使用 pytest、TDD 方法论、固件(Fixtures)、模拟(Mocking)、参数化及覆盖率要求的 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

Browse the most popular Claude skills, all testing & qa skills, or write your own with the skills generator.