pytest testing for Python applications: test-first development, unit, integration, composition, and end-to-end boundaries; fixtures, mocks, fakes, async tests, and database fidelity. Use when writing or debugging tests, deciding test levels, or configuring pytest. For FastAPI or SQLAlchemy mechanics, use their dedicated skills.
Ships in python. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Test behavior at useful boundaries. The right test level depends on the contract and failure risk.
Test at component boundaries, not internal implementation:
HTTP adapter → application use case → domain
↓
persistence adapter
Follow test → implement → refactor:
# Temporary skeleton, if one helps orient the code.
def calculate_discount(total: Decimal) -> Decimal:
raise NotImplementedError
# 2. Test
def test_discount_for_large_order():
result = calculate_discount(Decimal("150"))
assert result == Decimal("15")
# 3. Implement
def calculate_discount(total: Decimal) -> Decimal:
if total > 100:
return total * Decimal("0.1")
return Decimal("0")
Test what crosses layer boundaries, not internal implementation:
See references/boundaries.md for comprehensive layer-specific examples.
Test business logic without framework DTOs:
def test_product_apply_discount():
"""Test business logic"""
product = Product(id=uuid4(), name="Widget", price=Decimal("100"))
product.apply_discount(Decimal("0.1"))
assert product.price == Decimal("90")
Test orchestration with stubbed dependencies:
from unittest.mock import create_autospec
def test_create_product_service():
"""Test with mocked repository"""
mock_repo = create_autospec(ProductRepository, instance=True, spec_set=True)
mock_repo.save.return_value = Product(id=uuid4(), name="Widget")
service = ProductService(repo=mock_repo)
result = service.create(CreateProductRequest(name="Widget", price=Decimal("9.99")))
mock_repo.save.assert_called_once()
assert result.name == "Widget"
Test the production dialect for database-specific behavior:
@pytest.fixture
def test_db():
"""Fast adapter test; not a PostgreSQL fidelity test."""
engine = create_engine("sqlite:///:memory:")
Base.metadata.create_all(engine)
session = sessionmaker(bind=engine)()
yield session
session.close()
def test_repository_save(test_db):
"""Test database operations"""
repo = ProductRepository(test_db)
product = Product(id=uuid4(), name="Widget", price=Decimal("9.99"))
saved = repo.save(product)
assert saved.id == product.id
assert test_db.get(ProductRecord, product.id) is not None
Test HTTP layer with TestClient:
from fastapi.testclient import TestClient
def test_create_product_endpoint():
"""Test POST endpoint"""
client = TestClient(app)
response = client.post(
"/products",
json={"name": "Widget", "price": 9.99},
)
assert response.status_code == 201
assert response.json()["name"] == "Widget"
tests/
├── unit/
│ ├── test_entities.py # Entity + Value object tests
│ └── test_services.py # Service tests (with mocks)
├── integration/
│ ├── test_repositories.py # Repository tests (with DB)
│ └── test_endpoints.py # Router tests (with client)
└── conftest.py # Shared fixtures
For comprehensive patterns and examples, see:
With pytest-asyncio strict mode, mark async tests with @pytest.mark.asyncio and decorate async fixtures with @pytest_asyncio.fixture. Use AsyncMock and assert_awaited_once_with for async collaborators. See references/pytest.md for loop scopes and cleanup.
What SKILL.md sets; muted values are Claude Code's defaults
No slash command · from python
npx claudepluginhub martinffx/python-skills --plugin pythonOther plugins' skills for the same job
8 skills in this plugin
/python-architecturePython application architecture for complex business behavior: functional decisions and effects, ports and adapters, aggregates, transaction ownership, and bounded contexts. Use when choosing application or domain boundaries, modeling evolving invariants, or deciding whether DDD is warranted. Do not apply rich DDD layers automatically to simple CRUD or framework DTOs./python-build-toolsPython project tooling with uv, mise, Ruff, basedpyright, and pytest. Use for pyproject.toml, dependency groups, lockfiles, uv sync/run/build/publish, reproducible CI, Ruff, basedpyright, or Python tool-version setup. For uv multi-package layouts and Docker, use python-monorepo./python-fastapiFastAPI APIs with Pydantic, OpenAPI, dependencies, security, middleware, lifespan, and response models. Use for routes, validation, authentication or authorization, database-session dependencies, CORS, sync versus async handlers, pagination, errors, or startup and shutdown resources. For ORM mechanics, use python-sqlalchemy.