I Dance with Your Shadow: Patch, Stub, Mock
summary
Shows concrete Python testing techniques: how to patch the import location to replace objects in the runtime namespace, when to prefer dependency injection over patching, and the differences between Mock and MagicMock (including autospec and wrapper usage). Demonstrates asserting call patterns and return sequences, and tools for external interactions such as vcr‑pytest to record HTTP interactions and moto to fake AWS; reports benefits for CI speed and cost and warns about re‑recording and stale cassette risks.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 4:22Simulators
- 6:00Patching - Common Mistakes
- 8:02Patching - Decorator
- 9:15Patching - Context Manager
- 10:38Patching - Scopes
- 12:30Dependency Inversion
- 15:54Mocks - Specs
- 17:52Mock - Assertions
- 19:07VCR - A Recorder
related talks
49mFor those about to Mock I salute you!
20mMock, patch - when and how to use
39mIntro to Mocking: Why Unit Testing Doesn't Have To Be So Hard
31mHot-swapping Symbols During Tests: Demystifying unittest.mock[.patch]
37mDemystifying the Patch Function
29mUnit testing in the real world with mock
26mMocking: virtual reality for your Python tests
32mMock It Till You Make It: How to Verify Your External Mocks Without Ever...
