Skill python-pytest-ops
scriptsMengimplementasikan pola testing Python modern termasuk fixtures, parametrization, exception handling, dan mocking.
- Bintang GitHub
- 81
- File
- 12
- Commit terakhir
- 7 Nov 2026
- Lisensi
- MIT
- Tool yang diizinkan
- 3
Apa fungsi skill python-pytest-ops?
python-pytest-ops adalah agent skill. Mengimplementasikan pola testing Python modern termasuk fixtures, parametrization, exception handling, dan mocking.
Ringkasan dibuat dari SKILL.md skill ini.
Tentang skill python-pytest-ops
Skill ini memungkinkan Anda untuk menulis test suite yang komprehensif untuk aplikasi Python. Developer dapat menggunakannya untuk mengimplementasikan pola testing modern seperti fixtures, parametrization, dan exception handling dalam workflow testing mereka. Skill ini dirancang untuk engineer yang bekerja dengan Python 3.9 atau versi lebih tinggi dan pytest 7.0 atau yang terbaru, guna menyediakan struktur yang dibutuhkan untuk unit dan integration tests.
Agent harus memuat skill ini saat ditugaskan untuk membuat atau memperbaiki file test, mengelola shared test configuration melalui conftest.py, atau mensimulasikan dependensi eksternal menggunakan tools mocking seperti unittest.mock atau pytest-mock. Skill ini mengandalkan akses Bash untuk mengeksekusi command seperti pytest untuk menjalankan test, pytest-cov untuk membuat coverage reports, dan pytest-xdist untuk parallel execution. Skill ini membantu mengelola skenario test yang kompleks melalui berbagai fixture scopes, mulai dari fungsi individual hingga seluruh session.
Apa yang bisa dilakukan agent dengannya
- 1Membuat reusable test fixturesMenghasilkan logika setup dan teardown untuk koneksi database atau objek user menggunakan pytest fixtures.
- 2Menjalankan parameterized test casesMengeksekusi satu fungsi test terhadap berbagai set input dan nilai output yang diharapkan.
- 3Mock external API dependenciesMengganti network calls asli dengan mock objects yang terkontrol untuk mengisolasi kode yang sedang dites.
- 4Memverifikasi error handling logicMemastikan bahwa exception tertentu muncul ketika input yang tidak valid diberikan ke sebuah fungsi.
Ditulis dari SKILL.md milik skill tersebut. Setiap use case diverifikasi dengan kutipan darinya.
Cara install skill python-pytest-ops
Setiap perintah menyalin folder skill ke direktori skills client. Restart client atau mulai sesi baru untuk memuatnya.Install skill python-pytest-ops di Plugin
/plugin marketplace add 0xDarkMatter/claude-mods /plugin install claude-mods@claude-mods
Install skill python-pytest-ops di Claude Code
~/.claude/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.claude/skills/python-pytest-opsInstall skill python-pytest-ops di Claude Code (project)
.claude/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops .claude/skills/python-pytest-opsInstall skill python-pytest-ops di Codex
~/.agents/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.agents/skills/python-pytest-opsInstall skill python-pytest-ops di Gemini CLI
~/.gemini/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.gemini/skills/python-pytest-opsInstall skill python-pytest-ops di Claude.ai
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
Pengecekan otomatis
Berjalan 15 Nov 2026Laporan lengkap →Belum terverifikasi. Skill perlu skor 80, tanpa temuan serius, dan data yang cukup untuk kami cek. Cara kerja checks · Yang perlu diperbaiki untuk menambah poin
- Source repository terhubung dan dapat dijangkau0xdarkmatter/claude-mods/skills/python-pytest-ops is public and reachablegithub.com/0xdarkmatter/claude-mods/tree/HEAD/skills/python- ↗Lolos
- Lisensi open source (OSI)MITspdx.org/licenses/MIT.html ↗Lolos
- Ada commit atau release dalam satu tahun terakhirLast commit 2026-11-07github.com/0xdarkmatter/claude-mods/commits ↗Lolos
- Skrip tanpa unduh-lalu-jalankan atau pencurian kredensial2 scripts read; no download-and-run, remote eval, base64 execution or credential uploadLolos
- Tidak ada instruksi tersembunyi di SKILL.mdNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Lolos
- Tool yang diizinkan otomatis dibatasiBash lets the agent run any shell command without askinggithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Temuan
- SKILL.md mengikuti format Agent SkillsValid name and description; says when to use it; 207 linesgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Lolos
SKILL.md
Lihat di GitHubPython 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
Berkas dalam skill ini
12Pertanyaan seputar skill python-pytest-ops
Bagaimana cara install skill python-pytest-ops di Claude Code?
Jalankan npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.claude/skills/python-pytest-ops. Claude Code memuat skill dari ~/.claude/skills (semua proyek) atau .claude/skills (satu proyek) dan menggunakan skill saat deskripsinya cocok dengan tugas.
Client mana saja yang bisa menggunakan skill python-pytest-ops?
Client apa pun yang membaca format Agent Skills: Claude Code, Codex, Gemini CLI, dan claude.ai (unggah sebagai ZIP). Script dalam skill hanya berjalan di client yang mengizinkan eksekusi kode.
Apa saja pilihan fixture scopes yang tersedia di pytest?
Anda dapat menentukan fixture scopes sebagai function (default), class, module, atau session.
Bagaimana cara menjalankan hanya test yang telah ditandai sebagai 'slow'?
Gunakan command pytest -m slow untuk mengeksekusi test dengan marker spesifik tersebut.
Bagaimana cara mengetes apakah exception tertentu muncul?
Gunakan context manager pytest.raises untuk menangkap exception yang diharapkan dan secara opsional mencocokkannya dengan regex.