skills/python-testing/SKILL.md
Stub-Driven TDD and layer boundary testing with pytest. Use when writing tests, deciding what to test, testing at component boundaries, or implementing test-driven development.
npx skillsauth add martinffx/claude-code-atelier python-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Stub-Driven TDD and layer boundary testing patterns for Python applications.
Test at component boundaries, not internal implementation:
Router → Service → Repository → Entity → Database
↓ ↓ ↓ ↓
Test Test Test Test
Follow the Stub → Test → Implement → Refactor workflow:
pass# 1. Stub
def calculate_discount(total: Decimal) -> Decimal:
pass
# 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 transformations and business logic:
def test_product_from_request():
"""Test creation from request"""
request = CreateProductRequest(name="Widget", price=Decimal("9.99"))
product = Product.from_request(request)
assert product.name == "Widget"
assert product.price == Decimal("9.99")
assert isinstance(product.id, UUID)
def test_product_apply_discount():
"""Test business logic"""
product = Product(id=uuid4(), name="Widget", price=Decimal("100"))
discounted = product.apply_discount(Decimal("0.1"))
assert discounted.price == Decimal("90")
Test orchestration with stubbed dependencies:
from unittest.mock import Mock
def test_create_product_service():
"""Test with mocked repository"""
mock_repo = Mock()
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 data access with real test database:
@pytest.fixture
def test_db():
"""In-memory test database"""
engine = create_engine("sqlite:///:memory:")
Base.metadata.create_all(engine)
return sessionmaker(bind=engine)()
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.query(ProductRecord).count() == 1
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:
Progressive disclosure: SKILL.md provides quick reference, references/ contain full details.
development
Security architecture and threat modeling knowledge. Auto-invokes when designing features that handle untrusted data, authentication, authorization, external integrations, file uploads, or sensitive data. Provides risk assessment frameworks, trust boundary analysis, and security design principles — not implementation code.
testing
Adversarial review of non-trivial decisions using fresh-context scrutiny. Use when correctness matters more than speed, when stakes are high (production, security-sensitive logic, irreversible operations), or before committing significant architectural or implementation choices.
development
Compact the current conversation into a handoff document for another agent to pick up.
testing
Socratic interrogation of plans against the project's domain model and documented decisions. Use when the user wants to stress-test a plan, clarify terminology, or validate assumptions against existing domain language. Updates CONTEXT.md and ADRs inline as decisions crystallise.