python-pytest-ops skill
scriptsImplements modern Python testing patterns including fixtures, parametrization, exception handling, and mocking.
- GitHub stars
- 81
- Files
- 12
- Last commit
- Nov 7, 2026
- License
- MIT
- Allowed tools
- 3
What does the python-pytest-ops skill do?
python-pytest-ops implements modern Python testing patterns including fixtures, parametrization, exception handling, and mocking.
Summary generated from the skill's SKILL.md.
About the python-pytest-ops skill
Writing comprehensive test suites for Python applications is what this skill enables. Developers can use it to implement modern testing patterns such as fixtures, parametrization, and exception handling within their testing workflows. It is designed for engineers working with Python 3.9 or higher and pytest 7.0 or later, providing the structure needed for unit and integration tests.
An agent should load this skill when tasked with creating or improving test files, managing shared test configurations via conftest.py, or simulating external dependencies using mocking tools like unittest.mock or pytest-mock. The skill relies on Bash access to execute commands like pytest for running tests, pytest-cov for generating coverage reports, and pytest-xdist for parallel execution. It helps manage complex test scenarios through various fixture scopes, ranging from individual functions to entire sessions.
What an agent can do with it
- 1Create reusable test fixturesGenerate setup and teardown logic for database connections or user objects using pytest fixtures.
- 2Run parameterized test casesExecute a single test function against multiple sets of input and expected output values.
- 3Mock external API dependenciesReplace real network calls with controlled mock objects to isolate the code under test.
- 4Verify error handling logicEnsure that specific exceptions are raised when invalid inputs are provided to a function.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the python-pytest-ops skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the python-pytest-ops skill in Plugin
/plugin marketplace add 0xDarkMatter/claude-mods /plugin install claude-mods@claude-mods
Install the python-pytest-ops skill in Claude Code
~/.claude/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.claude/skills/python-pytest-opsInstall the python-pytest-ops skill in Claude Code (project)
.claude/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops .claude/skills/python-pytest-opsInstall the python-pytest-ops skill in Codex
~/.agents/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.agents/skills/python-pytest-opsInstall the python-pytest-ops skill in Gemini CLI
~/.gemini/skills/python-pytest-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.gemini/skills/python-pytest-opsInstall the python-pytest-ops skill in 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
Automated checks
Ran Nov 15, 2026Full report →Not verified yet. A skill needs a score of 80, no serious finding, and enough data for us to check. How checks work · What to fix for more points
- Source repository linked and reachable0xdarkmatter/claude-mods/skills/python-pytest-ops is public and reachablegithub.com/0xdarkmatter/claude-mods/tree/HEAD/skills/python- ↗Pass
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit 2026-11-07github.com/0xdarkmatter/claude-mods/commits ↗Pass
- No download-and-run or credential theft in scripts2 scripts read; no download-and-run, remote eval, base64 execution or credential uploadPass
- No hidden instructions in SKILL.mdNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Pass
- Pre-approved tools are scopedBash lets the agent run any shell command without askinggithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Finding
- SKILL.md follows the Agent Skills formatValid name and description; says when to use it; 207 linesgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Pass
SKILL.md
View on 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
Files in this skill
12python-pytest-ops skill questions
How do I install the python-pytest-ops skill in Claude Code?
Run npx degit 0xDarkMatter/claude-mods/skills/python-pytest-ops ~/.claude/skills/python-pytest-ops. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the python-pytest-ops skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
What are the different fixture scopes available in pytest?
You can define fixture scopes as function (default), class, module, or session.
How can I run only tests that have been marked as 'slow'?
Use the command pytest -m slow to execute tests with that specific marker.
How do I test if a specific exception is raised?
Use the pytest.raises context manager to catch expected exceptions and optionally match them against a regex.