python-testing

Solid

pytest、TDD手法、フィクスチャ、モック、パラメータ化、カバレッジ要件を使用したPythonテスト戦略。

Testing & QA 196,640 stars 30253 forks Updated 2 days ago MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

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