Comprehensive testing strategies for Python using pytest, fixtures, mocking, and test-driven development.
Works with
Covers unit, integration, functional, and performance testing with the AAA pattern (Arrange, Act, Assert) for test structure
Includes 10 fundamental and advanced patterns: basic tests, fixtures with setup/teardown, parameterization, mocking, exception handling, async testing, monkeypatching, temporary files, custom fixtures, and property-based testing
Provides test design princip
AI-first code editor with Composer
Before installing skills in Cursor, ensure your development environment meets these requirements:
node --versionpython-testing-patternsExecute the skills CLI command in your project's root directory to begin installation:
Fetches python-testing-patterns from wshobson/agents and configures it for Cursor.
The CLI shows a list of agents. Use arrow keys and space to select Cursor:
Confirm successful installation by checking the skill directory location:
Restart Cursor to activate python-testing-patterns. Access via /python-testing-patterns in your agent's command palette.
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Submit your Claude Code skill and start earning
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
2
total installs
2
this week
33.1K
GitHub stars
0
upvotes
Run in your terminal
2
installs
2
this week
33.1K
stars
Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.
# test_example.py
def add(a, b):
return a + b
def test_add():
"""Basic test example."""
result = add(2, 3)
assert result == 5
def test_add_negative():
"""Test with negative numbers."""
assert add(-1, 1) == 0
# Run with: pytest test_example.py
# test_calculator.py
import pytest
class Calculator:
"""Simple calculator for testing."""
def add(self, a: float, b: float) -> float:
return a + b
def subtract(self, a: float, b: float) -> float:
return a - b
def multiply(self, a: float, b: float) -> float:
return a * b
def divide(self, a: float, b: float) -> float:
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def test_addition():
"""Test addition."""
calc = Calculator()
assert calc.add(2, 3) == 5
assert calc.add(-1, 1) == 0
assert calc.add(0, 0) == 0
def test_subtraction():
"""Test subtraction."""
calc = Calculator()
assert calc.subtract(5, 3) == 2
assert calc.subtract(0, 5) == -5
def test_multiplication():
"""Test multiplication."""
calc = Calculator()
assert calc.multiply(3, 4) == 12
assert calc.multiply(0, 5) == 0
def test_division():
"""Test division."""
calc = Calculator()
assert calc.divide(6, 3) == 2
assert calc.divide(5, 2) == 2.5
def test_division_by_zero():
"""Test division by zero raises error."""
calc = Calculator()
with pytest.raises(ValueError, match="Cannot divide by zero"):
calc.divide(5, 0)
# test_database.py
import pytest
from typing import Generator
class Database:
"""Simple database class."""
def __init__(self, connection_string: str):
self.connection_string = connection_string
self.connected = False
def connect(self):
"""Connect to database."""
self.connected = True
def disconnect(self):
"""Disconnect from database."""
self.connected = False
def query(self, sql: str) -> list:
"""Execute query."""
if not self.connected:
raise RuntimeError("Not connected")
return [{"id": 1, "name": "Test"}]
@pytest.fixture
def db() -> Generator[Database, None, None]:
"""Fixture that provides connected database."""
# Setup
database = Database("sqlite:///:memory:")
database.connect()
# Provide to test
yield database
# Teardown
database.disconnect()
def test_database_query(db):
"""Test database query with fixture."""
results = db.query("SELECT * FROM users")
assert len(results) == 1
assert results[0]["name"] == "Test"
@pytest.fixture(scope="session")
def app_config():
"""Session-scoped fixture - created once per test session."""
return {
"database_url": "postgresql://localhost/test",
Implementation Guide
Prerequisites
- ›Claude Desktop or compatible AI client with skill support
- ›Clear understanding of task or problem to solve
- ›Willingness to iterate and refine outputs
Time Estimate
15-45 minutes depending on use case complexity
Steps
- 1Install skill using provided installation command
- 2Test with simple use case relevant to your work
- 3Evaluate output quality and relevance
- 4Iterate on prompts to improve results
- 5Integrate into regular workflow if valuable
Common Pitfalls
- ⚠Expecting perfect results without iteration
- ⚠Not providing enough context in prompts
- ⚠Using skill for tasks outside its intended scope
- ⚠Accepting outputs without review and validation
Best Practices
✓ Do
- +Start with clear, specific prompts
- +Provide relevant context and constraints
- +Review and refine all outputs before using
- +Iterate to improve output quality
- +Document successful prompt patterns
✗ Don't
- −Don't use without understanding skill limitations
- −Don't skip validation of outputs
- −Don't share sensitive information in prompts
- −Don't expect skill to replace human judgment
💡 Pro Tips
- ★Be specific about desired format and style
- ★Ask for multiple options to choose from
- ★Request explanations to understand reasoning
- ★Combine AI efficiency with human expertise
When to Use This
✓ Use when
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid when
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
Learning Path
- 1Familiarize yourself with skill capabilities and limitations
- 2Start with low-risk, non-critical tasks
- 3Progress to more complex and valuable use cases
- 4Build expertise through regular use and experimentation
Related Skills
python-code-style
10wshobson/agents
Backendsame repofastapi-python
73mindrally/skills
Backendtag: pythonpython-expert-best-practices-code-review
47wispbit-ai/skills
Backendtag: pythonpython-expert
27shubhamsaboo/awesome-llm-apps
Backendtag: pythonflask-python
11mindrally/skills
Backendtag: pythongolang-testing
9samber/cc-skills-golang
Backendtag: testingReviews
4.8★★★★★46 reviews- HHassan Menon★★★★★Dec 24, 2024
python-testing-patterns is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- MMei Huang★★★★★Dec 12, 2024
python-testing-patterns reduced setup friction for our internal harness; good balance of opinion and flexibility.
- SShikha Mishra★★★★★Dec 4, 2024
python-testing-patterns fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- YYash Thakker★★★★★Nov 23, 2024
python-testing-patterns is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- HHassan Bansal★★★★★Nov 15, 2024
python-testing-patterns fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- LLucas Farah★★★★★Nov 3, 2024
I recommend python-testing-patterns for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- TTariq Khan★★★★★Oct 22, 2024
Useful defaults in python-testing-patterns — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- DDhruvi Jain★★★★★Oct 14, 2024
Keeps context tight: python-testing-patterns is the kind of skill you can hand to a new teammate without a long onboarding doc.
- HHassan Thomas★★★★★Oct 6, 2024
We added python-testing-patterns from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- AAisha Abebe★★★★★Sep 25, 2024
Solid pick for teams standardizing on skills: python-testing-patterns is focused, and the summary matches what you get after install.
showing 1-10 of 46
1 / 5Discussion
Comments — not star reviews- No comments yet — start the thread.