How to mock dependencies in tests?
Answer
•Use unittest.mock (patch, MagicMock).
•Mock at the point of use, not definition.
•Prefer dependency injection where possible.
•Check calls: assert_called_once_with.
•Do not turn tests into copies of implementation.
Was this answer helpful?