test-doubles

Guides mocking, stubbing, fakes, and test isolation strategies for Python unit tests.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/Dazlarus/karl-code --skill test-doubles-dazlarus
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: test-doubles
Source: https://github.com/Dazlarus/karl-code/tree/main/.agents/skills/test-doubles
Command: npx skills add https://github.com/Dazlarus/karl-code --skill test-doubles-dazlarus

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing unit tests for code with external dependencies often leads to brittle, over-mocked, or slow tests. This Skill provides clear patterns for choosing the right test double—mocks, stubs, fakes, spies, or fixtures—so tests stay isolated, readable, and maintainable. ## Core Features & Use Cases - Test Double Selection Guidance: Distinguishes when to use mocks for behavior verification, stubs for test data, fakes for in-memory implementations, and spies for recording interactions. - Pytest Fixture and Factory Patterns: Shows how to build reusable fixtures with pytest and complex test data with factory_boy. - External API Test Recording: Demonstrates VCR.py cassettes for recording and replaying HTTP interactions in API tests. - Use Case: When writing tests for a user service that calls an email API, apply this Skill to mock only the external API, use a fake repository for storage, and avoid over-mocking internal logic. ## Quick Start Review my test file and recommend the right test doubles for isolating the external API calls.

Frequently Asked Questions about test-doubles

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I mock external API calls in Python tests?▼

Use unittest.mock's patch to replace external calls like requests.post, or use VCR.py to record and replay real HTTP interactions from cassette files. Mock only the external boundary, not internal logic, to keep tests meaningful.

What is the difference between mocks, stubs, and fakes?▼

Mocks verify behavior by asserting calls were made, stubs provide canned test data, and fakes are working in-memory implementations like a dictionary-backed repository. Choose based on whether you need behavior verification, data, or lightweight functionality.

When should I use pytest fixtures versus factory_boy?▼

Use pytest fixtures for simple, reusable test data shared across tests. Use factory_boy when you need complex objects with generated sequences, fake names, or many variations of model instances.

Why is over-mocking a problem in unit tests?▼

Over-mocking internal implementation details creates brittle tests that break on refactoring without catching real bugs. Only mock external dependencies like APIs or databases, and test actual internal logic directly.

Can I use VCR.py to test APIs without network access?▼

Yes, VCR.py records real HTTP interactions into YAML cassette files on first run, then replays them offline in subsequent test runs. This makes API tests fast, deterministic, and independent of network availability.