Testing
Mocking and Patching
Isolating units of code by mocking dependencies
Interview: Testing architecture — all levels
Mocking
Mocking replaces real dependencies with controlled stand-ins. Python's unittest.mock provides Mock, MagicMock, and patch decorators.
When to Mock
- External API calls (HTTP requests, database queries)
- File system operations (slow, environment-dependent)
- Third-party services (payment gateways, email providers)