python-pytest-ops skill
scriptsfixture、パラメータ化、例外処理、mockingを含むモダンなPythonテストパターンを実装します。
- GitHubスター
- 81
- ファイル
- 12
- 最終コミット
- 2026年11月7日
- ライセンス
- MIT
- 許可されたツール
- 3
python-pytest-ops skillは何をしますか
python-pytest-opsはAgent Skillsです。 fixture、パラメータ化、例外処理、mockingを含むモダンなPythonテストパターンを実装します。.
skillのSKILL.mdから生成された要約。
python-pytest-ops skill について
このSKILLは、Pythonアプリケーション向けの包括的なテストスイートの作成を可能にします。開発者は、テストワークフロー内でfixture、パラメータ化、例外処理などのモダンなテストパターンを実装するためにこれを利用できます。Python 3.9以上およびpytest 7.0以降を使用するエンジニア向けに設計されており、ユニットテストや統合テストに必要な構造を提供します。
エージェントがテストファイルの作成や改善、conftest.pyによる共有テスト設定の管理、またはunittest.mockやpytest-mockなどのmockingツールを使用した外部依存関係のシミュレーションを求められた場合に、このSKILLをロードする必要があります。このSKILLは、テスト実行のためのpytest、カバレッジレポート生成のためのpytest-cov、並列実行のためのpytest-xdistなどのコマンドを実行するためにBashへのアクセスを利用します。個々の関数からセッション全体に至るまで、さまざまなfixtureスコープを通じて複雑なテストシナリオの管理を支援します。
エージェントができること
- 1再利用可能なテストfixtureの作成pytest fixtureを使用して、データベース接続やユーザーオブジェクトのセットアップおよびティアダウンのロジックを生成します。
- 2パラメータ化されたテストケースの実行単一のテスト関数に対して、複数の入力値と期待される出力値のセットを実行します。
- 3外部API依存関係のmock実際のネットワークコールを制御されたmockオブジェクトに置き換え、テスト対象のコードを分離します。
- 4エラーハンドリングロジックの検証関数に無効な入力が提供されたときに、特定の例外が確実に発生することを確認します。
skill の SKILL.md から作成されています。すべてのユースケースは、その引用と照合されています。
python-pytest-ops skillのインストール方法
各コマンドはskillフォルダをクライアントのskillsディレクトリにコピーします。読み込むには、クライアントを再起動するか新しいセッションを開始してください。プラグインにpython-pytest-ops skillをインストールする
/plugin marketplace add 0xDarkMatter/claude-mods /plugin install claude-mods@claude-mods
Claude Codeにpython-pytest-ops skillをインストールする
~/.claude/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.claude/skills/python-pytest-opsClaude Code (project)にpython-pytest-ops skillをインストールする
.claude/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops .claude/skills/python-pytest-opsCodexにpython-pytest-ops skillをインストールする
~/.agents/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.agents/skills/python-pytest-opsGemini CLIにpython-pytest-ops skillをインストールする
~/.gemini/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.gemini/skills/python-pytest-opsClaude.aiにpython-pytest-ops skillをインストールする
npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops python-pytest-ops && zip -r python-pytest-ops.zip python-pytest-ops # claude.ai → Customize → Skills → + → Create skill → Upload a skill → python-pytest-ops.zip
自動チェック
実行日 2026年11月15日完全なレポート →まだ検証されていません。スキルにはスコア 80、重大な指摘なし、チェックに十分なデータが必要です。 チェックの仕組み · 点数を上げるための改善点
- ソースリポジトリがリンクされており、アクセス可能0xdarkmatter/claude-mods/skills/python-pytest-ops is public and reachablegithub.com/0xdarkmatter/claude-mods/tree/HEAD/skills/python- ↗合格
- オープンソースライセンス (OSI)MITspdx.org/licenses/MIT.html ↗合格
- 過去1年以内にコミットまたはリリースありLast commit 2026-11-07github.com/0xdarkmatter/claude-mods/commits ↗合格
- スクリプトにダウンロード実行や認証情報の窃取がない2 scripts read; no download-and-run, remote eval, base64 execution or credential upload合格
- SKILL.md に隠れた指示がないNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗合格
- 事前許可ツールが限定されているBash lets the agent run any shell command without askinggithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗検出事項
- SKILL.md が Agent Skills の形式に従っているValid name and description; says when to use it; 207 linesgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗合格
SKILL.md
GitHubで表示Python pytest Patterns
Modern pytest patterns for effective testing.
Basic Test Structure
import pytest
def test_basic():
"""Simple assertion test."""
assert 1 + 1 == 2
def test_with_description():
"""Descriptive name and docstring."""
result = calculate_total([1, 2, 3])
assert result == 6, "Sum should equal 6"
Fixtures
import pytest
@pytest.fixture
def sample_user():
"""Create test user."""
return {"id": 1, "name": "Test User"}
@pytest.fixture
def db_connection():
"""Fixture with setup and teardown."""
conn = create_connection()
yield conn
conn.close()
def test_user(sample_user):
"""Fixtures injected by name."""
assert sample_user["name"] == "Test User"
Fixture Scopes
@pytest.fixture(scope="function") # Default - per test
@pytest.fixture(scope="class") # Per test class
@pytest.fixture(scope="module") # Per test file
@pytest.fixture(scope="session") # Entire test run
Parametrize
@pytest.mark.parametrize("input,expected", [
(1, 2),
(2, 4),
(3, 6),
])
def test_double(input, expected):
assert double(input) == expected
# Multiple parameters
@pytest.mark.parametrize("x", [1, 2])
@pytest.mark.parametrize("y", [10, 20])
def test_multiply(x, y): # 4 test combinations
assert x * y > 0
Exception Testing
def test_raises():
with pytest.raises(ValueError) as exc_info:
raise ValueError("Invalid input")
assert "Invalid" in str(exc_info.value)
def test_raises_match():
with pytest.raises(ValueError, match=r".*[Ii]nvalid.*"):
raise ValueError("Invalid input")
Markers
@pytest.mark.skip(reason="Not implemented yet")
def test_future_feature():
pass
@pytest.mark.skipif(sys.platform == "win32", reason="Unix only")
def test_unix_feature():
pass
@pytest.mark.xfail(reason="Known bug")
def test_buggy():
assert broken_function() == expected
@pytest.mark.slow
def test_performance():
"""Custom marker - register in pytest.ini."""
pass
Mocking
from unittest.mock import Mock, patch, MagicMock
def test_with_mock():
mock_api = Mock()
mock_api.get.return_value = {"status": "ok"}
result = mock_api.get("/endpoint")
assert result["status"] == "ok"
@patch("module.external_api")
def test_with_patch(mock_api):
mock_api.return_value = {"data": []}
result = function_using_api()
mock_api.assert_called_once()
pytest-mock (Recommended)
def test_with_mocker(mocker):
mock_api = mocker.patch("module.api_call")
mock_api.return_value = {"success": True}
result = process_data()
assert result["success"]
conftest.py
# tests/conftest.py - Shared fixtures
import pytest
@pytest.fixture(scope="session")
def app():
"""Application fixture available to all tests."""
return create_app(testing=True)
@pytest.fixture
def client(app):
"""Test client fixture."""
return app.test_client()
Quick Reference
Run these inside the project env — prefix with uv run (e.g. uv run pytest -v).
Bare pytest is shown below for brevity.
| Command | Description |
|---|---|
pytest |
Run all tests |
pytest -v |
Verbose output |
pytest -x |
Stop on first failure |
pytest -k "test_name" |
Run matching tests |
pytest -m slow |
Run marked tests |
pytest --lf |
Rerun last failed |
pytest --cov=src |
Coverage report |
pytest -n auto |
Parallel (pytest-xdist) |
Additional Resources
./references/fixtures-advanced.md- Factory fixtures, autouse, conftest patterns./references/mocking-patterns.md- Mock, patch, MagicMock, side_effect./references/async-testing.md- pytest-asyncio patterns./references/coverage-strategies.md- pytest-cov, branch coverage, reports./references/integration-testing.md- Database fixtures, API testing, testcontainers./references/property-testing.md- Hypothesis framework, strategies, shrinking./references/test-architecture.md- Test pyramid, organization, isolation strategies
Scripts
./scripts/run-tests.sh- Run tests with recommended options./scripts/generate-conftest.sh- Generate conftest.py boilerplate
Assets
./assets/pytest.ini.template- Recommended pytest configuration./assets/conftest.py.template- Common fixture patterns
See Also
Related Skills:
python-typing-ops- Type-safe test codepython-async-ops- Async test patterns (pytest-asyncio)
Testing specific frameworks:
python-fastapi-ops- TestClient, API testingpython-database-ops- Database fixtures, transactions
このスキルのファイル
12python-pytest-ops skillに関する質問
Claude Codeにpython-pytest-ops skillをインストールするには
npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.claude/skills/python-pytest-opsを実行してください。Claude Codeは~/.claude/skills(すべてのプロジェクト)または.claude/skills(単一プロジェクト)からskillsを読み込み、説明がタスクに一致する場合にskillを使用します。
python-pytest-ops skillはどのクライアントで使用できますか
Agent Skills形式を読み込むすべてのクライアントで使用できます: Claude Code、Codex、Gemini CLI、claude.ai(ZIPとしてアップロード)。skill内のスクリプトは、クライアントがコード実行を許可した場合にのみ実行されます。
pytestで利用可能なfixtureのスコープにはどのようなものがありますか?
fixtureのスコープは、function(デフォルト)、class、module、またはsessionとして定義できます。
'slow'とマークされたテストのみを実行するにはどうすればよいですか?
pytest -m slowコマンドを使用して、その特定のマーカーを持つテストを実行します。
特定の例外が発生するかどうかをテストするにはどうすればよいですか?
pytest.raisesコンテキストマネージャーを使用して、期待される例外をキャッチし、オプションで正規表現による照合を行うことができます。