Mocking of mocks. A deep dive into the mock module
summary
An in-depth look at Python’s mock module, explaining how to create and use mock objects for testing. Covers techniques for nesting and composing mocks, common pitfalls when mocking dependencies, and practical examples using the mock API (patch, MagicMock, side_effect, etc.).
AI-written summary · about
chapters (17)
- 0:00Mocks in Python
- 1:26Why use mocks?
- 3:12Basic Mocks
- 5:40MagicMock vs Mock
- 7:03Side effects in mocks
- 8:06Mocking functions
- 8:27Mock patch for dependencies
- 10:34Common mock problems
- 11:37Spec and autospec in Python 3.7
- 13:23Mocking real objects
- 14:25Sentinels in mocks
- 15:27How patch works
- 16:54Correct patching scope
- 17:36Named mocks
- 18:20Verify mock calls
- 19:23Practical mock example
- 21:31Common errors and fixes
related talks
39mIntro to Mocking: Why Unit Testing Doesn't Have To Be So Hard
20mMock, patch - when and how to use
49mFor those about to Mock I salute you!
26mMocking: virtual reality for your Python tests
29mUnit testing in the real world with mock
32mMock It Till You Make It: How to Verify Your External Mocks Without Ever...
27mI Dance with Your Shadow: Patch, Stub, Mock
45mStop Using Mocks (for a while)
