python3-testing
Testing Patterns
Consult python3-core for standing defaults (coverage, test naming, AAA).
Test Failure Mindset
Tests are specifications. When a test fails, investigate both possibilities:
| Hypothesis A | Hypothesis B |
|---|---|
| Test expectations are wrong | Implementation has a bug |
| Test is outdated | Test caught a regression |
| Test has wrong assumptions | Test found an edge case |
Red flags: Never immediately change tests to match implementation. Never assume implementation is always correct. Never bulk-update tests without individual analysis.
Fixture Design
- Session fixtures for expensive resources (DB, servers)
- Module fixtures for shared test data
- Function fixtures for isolated per-test data
- Factory pattern for complex test objects
from pathlib import Path
from string import Template
FIXTURES_DIR = Path(__file__).parent / "fixtures"
@pytest.fixture
def mock_binary(tmp_path: Path) -> Path:
template_path = FIXTURES_DIR / "binaries" / "mock_binary_template.sh"
template = Template(template_path.read_text())
content = template.substitute(binary_name="tool", version="1.0.0")
binary = tmp_path / "tool"
binary.write_text(content)
binary.chmod(0o755)
return binary
Coverage Targets
| Code Type | Minimum |
|---|---|
| Business logic | 90% |
| Standard code | 80% |
| Scripts/utilities | 70% |
| Critical paths | 95% + mutation testing |
# pyproject.toml
[tool.coverage.run]
branch = true
source = ["src"]
omit = ["**/tests/**"]
[tool.coverage.report]
fail_under = 80
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
"raise NotImplementedError",
]
Property-Based Testing
When Hypothesis is available:
- Round-trip tests for parsers/serializers
- Invariant tests for state machines
- Boundary validation with
@given(st.from_type(T))
from hypothesis import given, strategies as st
@given(st.lists(st.integers()))
def test_sort_maintains_length(data: list[int]) -> None:
"""Sorting preserves all elements."""
result = sorted(data)
assert len(result) == len(data)
Mutation Testing
For critical code (payments, auth, data validation):
uv run mutmut run --paths-to-mutate=packages/module/
uv run mutmut results
Target: >90% mutation score for critical code paths.
Test Directory Structure
tests/
├── conftest.py # Shared fixtures
├── unit/ # Fast, isolated tests
├── integration/ # Tests with external dependencies
├── e2e/ # End-to-end workflows
└── fixtures/ # Test data files
References
references/testing-standards.md— full testing standardsreferences/agent-prompts.md— agent test promptsreferences/plan-templates.md— test plan templates
More from jamie-bitflight/claude_skills
perl-lint
This skill should be used when the user asks to lint Perl code, run perlcritic, check Perl style, format Perl code, run perltidy, or mentions Perl Critic policies, code formatting, or style checking.
24brainstorming-skill
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or when users request help with ideation, marketing, and strategic planning. Explores user intent, requirements, and design before implementation using 30+ research-validated prompt patterns.
11design-anti-patterns
Enforce anti-AI UI design rules based on the Uncodixfy methodology. Use when generating HTML, CSS, React, Vue, Svelte, or any frontend UI code. Prevents "Codex UI" — the generic AI aesthetic of soft gradients, floating panels, oversized rounded corners, glassmorphism, hero sections in dashboards, and decorative copy. Applies constraints from Linear/Raycast/Stripe/GitHub design philosophy: functional, honest, human-designed interfaces. Triggers on: UI generation, dashboard building, frontend component creation, CSS styling, landing page design, or any task producing visual interface code.
7python3-review
Comprehensive Python code review checking patterns, types, security, and performance. Use when reviewing Python code for quality issues, when auditing code before merge, or when assessing technical debt in a Python codebase.
7hooks-guide
Cross-platform hooks reference for AI coding assistants — Claude Code, GitHub Copilot, Cursor, Windsurf, Amp. Covers hook authoring in Node.js CJS and Python, per-platform event schemas, inline-agent hooks and MCP in agent frontmatter, common JSON I/O, exit codes, best practices, and a fetch script to refresh docs from official sources. Use when writing, reviewing, or debugging hooks for any AI assistant.
7agent-creator
Create high-quality Claude Code agents from scratch or by adapting existing agents as templates. Use when the user wants to create a new agent, modify agent configurations, build specialized subagents, or design agent architectures. Guides through requirements gathering, template selection, and agent file generation following Anthropic best practices (v2.1.63+).
6