python-testing
Solidpytest、TDD手法、フィクスチャ、モック、パラメータ化、カバレッジ要件を使用したPythonテスト戦略。
Testing & QA 196,640 stars
30253 forks Updated 2 days ago MIT
Install
Quality Score: 93/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# 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
...
Details
- Author
- affaan-m
- Repository
- affaan-m/everything-claude-code
- Created
- 4 months ago
- Last Updated
- 2 days ago
- Language
- JavaScript
- License
- MIT
Integrates with
Related Skills
Testing & QA Featured
rtk-tdd
Enforces TDD (Red-Green-Refactor) for Rust development. Auto-triggers on implementation, testing, refactoring, and bug fixing tasks. Provides Rust-idiomatic testing patterns with anyhow/thiserror, cfg(test), and Arrange-Act-Assert workflow.
55,551 Updated today
rtk-ai Testing & QA Featured
tdd-rust
TDD workflow for RTK filter development. Red-Green-Refactor with Rust idioms. Real fixtures, token savings assertions, snapshot tests with insta. Auto-triggers on new filter implementation.
55,551 Updated today
rtk-ai Testing & QA Featured
wordpress-penetration-testing
Assess WordPress installations for common vulnerabilities and WordPress 7.0 attack surfaces.
38,979 Updated today
sickn33