Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use Python mocks and fakes as a design tool without losing behavioral confidence. Use when testing external dependencies, choosing monkeypatch versus unittest.mock.patch, isolating slow boundaries, avoiding mock-heavy tests, interpreting mock call assertions, or refactoring toward clearer dependency seams.
.claude/skills/hashgraph-online-python-mock-isolation-design/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 1% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 3% | 0% |
| case-21 | ✓→✗ | ▼ Worse | -8% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 3% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 31% | 0% |
Use this skill when replacing a dependency in a Python test changes what the test proves. Mocks are useful at slow, nondeterministic, or external boundaries; they become harmful when they replace the behavior the test is supposed to validate.
Primary source: Harry Percival, Test-Driven Development with Python, 3rd ed. Guidance is transformed and paraphrased from chapters 20, 21, 27, and Appendix A, especially manual monkeypatching, unittest.mock.patch, mock coupling, call argument inspection, test isolation, and the architectural route out of mock-heavy suites.
patch when replacing a collaborator looked up by the module under test.Read mock-isolation-patterns.md for replacement choices and smell handling.
mock.return_value and side_effect deliberately; do not let default mocks create imaginary object graphs.MagicMock objects without specs for important interfaces.django-targeted-mocking for Django-specific boundaries.Before finishing, record:
Other measured skills in the registry, with their headline benchmark lift.