Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Explains when to use Python mocks, fakes, and patching for test isolation while keeping behavioral assertions primary.
Use this skill ↓86% 91%+5 ptsof test cases passed
Passed 20 of 22 test cases with the skill, and 19 of 22 without it.
We are auditing our python unit tests for `report_generator.py` which reads template files from disk. Give guidance on isolation choices and record the mandatory verification summary before concluding.
records the fake, patch, or real dependency choice made
3 of 3 safety checks passed
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.
Name the boundary.
Choose the replacement.
patch when replacing a collaborator looked up by the module under test.Keep behavior assertions primary.
Watch for design feedback.
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.Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.