macalbert/envilder/python-test-doubles
Claude Code and agent skill by macalbert/envilder
- community
Checking that the SKILL.md file is still in the repository.
Test doubles with unittest.mock (Mock, AsyncMock, patch) and Mother pattern. Use when creating test data, mocking dependencies, or setting up fixtures in Python tests.
Install
npx vskill@latest install macalbert/envilder/python-test-doublesSKILL.md
Test Doubles (Python)
This skill defines how to use test doubles in Python (unittest.mock + pytest).
Test Doubles Types
1. Mock: Mock / AsyncMock
Use Mock and AsyncMock to create mock objects for protocol interfaces.
Purpose: Replace real dependencies with controllable test doubles.
MANDATORY: Always use spec=InterfaceClass to catch typos at test time.
2. Stub: return_value / side_effect
Use return_value or side_effect to configure stubs.
Purpose: Predefined responses without caring about call verification.
3. Spy: wraps
Use wraps to observe calls on real objects without replacing behavior.
Purpose: Verify interactions while preserving real implementation.
4. Module Patch: patch / patch.object
Use patch to replace module-level objects or class methods.
Purpose: Replace external dependencies (boto3, file I/O, etc.).
5. Error Simulation: side_effect with Exception
Use side_effect with an exception to simulate failures.
Purpose: Test error paths and exception handling.
Verification Patterns
Basic Verification
Not Called
Call Count
Argument Inspection
Async Verification
Pytest Fixtures as Factories
Use fixtures to build test doubles with proper lifecycle:
Mother Pattern
Use factory functions or classes for reusable test data:
Usage:
Summary
| Double Type | Python API | Purpose | |
|---|---|---|---|
| Mock | Mock(spec=X) | Controllable replacement | |
| Stub | .return_value / .side_effect | Predefined responses | |
| Spy | Mock(wraps=real) | Observe real objects | |
| Patch | @patch("module.obj") | Replace module-level deps | |
| Error sim | .side_effect = Exception(...) | Failure paths |
When writing tests:
- Create port mocks with
Mock(spec=Interface)in fixtures - Configure stubs with
.return_valuein Arrange - Always verify mock interactions in Assert
- Use Mother pattern for complex test data
- Always use `spec=` to catch typo bugs
- Prefer fixture injection over inline
Mock()creation
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/python-test-doubles/SKILL.md
Popularity
- Repository stars
- 135
- Repository forks
- 4
- 7-day trend score
- 25
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/macalbert/envilder/python-test-doubles)