From python3-development
Designs pytest test suite architecture and coverage for Python 3.11+ projects: fixtures, parametrization, test pyramid, AAA pattern, unit/integration/E2E strategies.
npx claudepluginhub jamie-bitflight/claude_skills --plugin python3-developmentThis skill uses the workspace's default tool permissions.
Guidance for designing pytest test suites with modern Python 3.11+ patterns.
Designs pytest test suite architecture, plans coverage strategies, and reviews structure for Python 3.11+ projects. Guides test pyramid, fixtures, parametrization, async testing, and property-based approaches.
Implements strict pytest configurations for Python projects, covering fixtures, parametrize, coverage thresholds, async tests with pytest-asyncio, Hypothesis property testing, nox/tox, CI matrices, snapshot testing with syrupy, mocking, and test organization mirroring source code.
Provides pytest patterns for Python testing: setup, fixtures, TDD, mocking, async tests, and integration tests. Use for unit/integration test construction and coverage config.
Share bugs, ideas, or general feedback.
Guidance for designing pytest test suites with modern Python 3.11+ patterns.
Use this skill for test design decisions:
For test implementation, use the python-pytest-architect agent instead.
Consult ../python3-development/references/python3-standards.md when aligning test strategy with shared plugin testing norms. The strategies below supplement that document; they do not replace it.
Structure test suites following the test pyramid:
/\
/ \ E2E (few, slow, high confidence)
/----\
/ \ Integration (moderate, medium speed)
/--------\
/ \ Unit (many, fast, focused)
/------------\
Distribution targets:
Use behavioral naming that describes what is being tested:
# Pattern: test_{function}_{scenario}_{expected_result}
def test_validate_email_with_invalid_format_raises_validation_error():
"""Validate that malformed emails are rejected."""
...
def test_process_payment_when_insufficient_funds_returns_declined():
"""Payment processing declines when balance is insufficient."""
...
Structure every test with clear sections:
def test_user_registration_creates_account():
# Arrange
user_data = {"email": "test@example.com", "name": "Test User"}
repository = InMemoryUserRepository()
service = UserService(repository)
# Act
result = service.register(user_data)
# Assert
assert result.success is True
assert repository.count() == 1
from hypothesis import given, strategies as st
@given(st.lists(st.integers()))
def test_sort_maintains_length(data):
"""Sorting preserves all elements."""
result = sorted(data)
assert len(result) == len(data)
Organize fixtures by scope and purpose:
conftest.py (root)
├── Session fixtures (db connections, servers)
├── Module fixtures (shared test data)
└── Function fixtures (isolated per-test data)
tests/
├── conftest.py # Shared fixtures
├── unit/
│ └── conftest.py # Unit-specific fixtures
└── integration/
└── conftest.py # Integration-specific fixtures
Use factories for complex test objects:
import factory
from datetime import datetime, UTC
class UserFactory(factory.Factory):
class Meta:
model = User
id = factory.Sequence(lambda n: n)
email = factory.LazyAttribute(lambda o: f"user{o.id}@example.com")
created_at = factory.LazyFunction(lambda: datetime.now(UTC))
| Code Type | Minimum Coverage |
|---|---|
| Business logic | 90% |
| Standard code | 80% |
| Scripts/utilities | 70% |
| Critical paths | 95% + mutation testing |
# pyproject.toml
[tool.coverage.run]
branch = true
source = ["packages"]
omit = ["**/tests/**", "**/__pycache__/**"]
[tool.coverage.report]
fail_under = 80
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
"raise NotImplementedError",
]
Apply mutation testing to security-critical and payment-related code:
# Run mutation tests on auth module
uv run mutmut run --paths-to-mutate=packages/auth/
# View surviving mutants
uv run mutmut results
Target: >90% mutation score for critical code paths
tests/
├── conftest.py # Shared fixtures, pytest plugins
├── unit/ # Fast, isolated tests
│ ├── test_validators.py
│ └── test_models.py
├── integration/ # Tests with external dependencies
│ ├── test_database.py
│ └── test_api_client.py
├── e2e/ # End-to-end workflows
│ └── test_user_flows.py
├── fixtures/ # Test data files
│ ├── sample_config.yaml
│ └── test_data.json
└── conftest.py # Root-level configuration
python3-development:python-pytest-architect for test implementationpython3-development for general Python patterns/python3-development:modernpython for modern Python syntax reference