Skip to content
Agentmart
Submit a tool

python-testing

使用pytest、TDD方法、夹具、模拟、参数化和覆盖率要求的Python测试策略。

Skill by Luohaothu

IndexedMIT★ 26
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/luohaothu-python-testing

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

使用pytest、TDD方法、夹具、模拟、参数化和覆盖率要求的Python测试策略。

Use cases: testing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/python-testing

What's inside

Skill name
python-testing
Description
使用pytest、TDD方法、夹具、模拟、参数化和覆盖率要求的Python测试策略。
License
MIT
Instructions
812 lines in SKILL.md · view on GitHub

Before installing

  • Instructions call the network

Agent Skills spec issues

  • body: 812 lines (spec recommends under 500)

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Python 测试模式

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

## 何时激活

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

## 核心测试理念

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

始终遵循 TDD 循环:

1. **红**:为期望的行为编写一个失败的测试
2. **绿**:编写最少的代码使测试通过
3. **重构**:在保持测试通过的同时改进代码

```python
# Step 1: Write failing test (RED)
def test_add_numbers():
    result = add(2, 3)
    assert result == 5

# Step 2: Write minimal implementation (GREEN)
def add(a, b):
    return a + b

# Step 3: Refactor if needed (REFACTOR)
```

### 覆盖率要求

* **目标**:80%+ 代码覆盖率
* **关键路径**:需要 100% 覆盖率
* 使用 `pytest --cov` 来测量覆盖率

```bash
pytest --cov=mypackage --cov-report=term-missing --cov-report=html
```

## pytest 基础

### 基本测试结构

```python
import pytest

def test_addition():
    """Test basic addition."""
    assert 2 + 2 == 4

def test_string_uppercase():
    """Test string uppercasing."""
    text = "hello"
    assert text.upper() == "HELLO"

def test_list_append():
    """Test list append."""
    items = [1, 2, 3]
    items.append(4)
    assert 4 in items
    assert len(items) == 4
```

### 断言

```python
# Equality
assert result == expected

# Inequality
assert result != unexpected

# Truthiness
assert result  # Truthy
assert not result  # Falsy
assert result is True  # Exactly True
assert result is False  # Exactly False
assert result is None  # Exactly None

# Membership
assert item in collection
assert item not in collection

# Comparisons
assert result > 0
assert 0 <= result <= 100

# Type checking
assert isinstance(result, str)

# Exception testing (preferred approach)
with pytest.raises(ValueError):
    raise ValueError("error message")

# Check exception message
with pytest.raises(ValueError, match="invalid input"):
    raise ValueError("invalid input provided")

# Check exception attributes
with pytest.raises(ValueError) as exc_info:
    raise ValueError("error message")
assert str(exc_info.value) == "error message"
```

## 夹具

### 基本夹具使用

```python
import pytest

@pytest.fixture
def sample_data():
    """Fixture providing sample data."""

From Luohaothu/everything-codex, MIT.

More from Luohaothu/everything-codex

Signals

Stars
26
Forks
5
Open issues
0
Last commit (this folder)
Feb 5, 2026 (8 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Luohaothu

Cite this page

python-testing skill. Agent Mart. https://agentmart.dev/skills/luohaothu-python-testing (last updated 2026-10-24)