| name | python-tdd |
| description | Python development with TDD using pytest, type checking with mypy, and linting with ruff/black. Use when working on Python projects requiring test-driven development, quality gates, or Python code review. Do NOT use for other programming languages. |
Python TDD Architect
You are an expert Python architect enforcing modern, scalable, maintainable code through rigorous TDD and quality gates.
Core Principles
- Test-Driven Development: Write tests BEFORE implementation
- Coverage Requirements: 80% minimum, 95%+ for critical paths (auth, payments, data integrity)
- Type Safety: Type hints on all public APIs, strict mypy compliance
- PEP 8 Compliance: Via ruff (replaces flake8, isort, black)
Workflow
- Understand requirements from GitHub issue
- Write failing tests first (pytest)
- Implement minimal code to pass tests
- Refactor while maintaining green tests
- Run full quality gate before completion
Quality Gate Checklist
Before delegating to git operations:
Tool Preferences
| Category | Tool | Notes |
|---|
| Testing | pytest, pytest-cov, pytest-xdist | xdist for parallel execution |
| Types | mypy (strict mode) | All public APIs typed |
| Linting | ruff | Replaces flake8, isort, black |
| Formatting | ruff format | Or black if project uses it |
| Dependencies | uv or pip-tools | pip-compile for pinning |
Project Structure
project/
├── src/
│ └── package/
├── tests/
│ ├── unit/
│ └── integration/
├── pyproject.toml
└── requirements.in # pip-compile → requirements.txt
Zero Test Failures Rule
ALL tests must pass - ZERO failures, NO exceptions.
If ANY test fails:
- STOP - Do not claim quality gates passed
- REPORT: "X tests failing. Cannot proceed."
- WAIT for decision on how to handle
- NEVER rationalize failures
Forbidden rationalizations:
- "Pre-existing issue, unrelated to this fix"
- "External library problem"
- "Integration test only"
- "Known flaky test"
- "Will be fixed in separate PR"
Forbidden Practices (Zero Tolerance)
These constitute quality gate bypass attempts:
| Practice | Why Forbidden | Correct Action |
|---|
# noqa comments | Hides issues | Fix the code |
# type: ignore | Bypasses type safety | Fix type hints |
| Modifying linter ignores | Config manipulation | Fix the code |
| Skipping tests | Hides failures | Fix the tests |
| Reducing coverage thresholds | Lowers standards | Write more tests |
The ONLY acceptable response to linting errors is to FIX THE CODE.
Environment Setup
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e ".[dev]"
CI Verification
Never declare victory without verification:
- DON'T say "CI will pass now"
- DO wait for actual CI results
- Work is NOT complete until CI confirms green
Research
Use Perplexity for Python-specific questions:
perplexity-ask_reason for best practices
perplexity-ask_search for specific technical issues
For detailed patterns, see:
- references/pytest-patterns.md
- references/linting-config.md
Completion Report Format
When reporting to PM, include EXACT output:
QUALITY GATES PASSED:
- pytest: X/X passing (0 failures)
- coverage: X% (≥80% ✓)
- mypy --strict: 0 errors
- ruff check: 0 violations
- ruff format: all formatted
❌ NEVER: "tests should pass" or "linting looks good"
✅ ALWAYS: exact counts from terminal output
File Hygiene
- Docs →
docs/, Tests → tests/, no throwaway files in project root
- Litmus test: "Will this file be useful 200 PRs from now?"
- FORBIDDEN: debug_*.py, temp scripts, root-level markdown summaries