Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pytest: Mocking - why?

  • Testing environment that does not depend on external systems.
  • Faster tests (mock remote calls, mock whole databases, etc.)
  • Fake some code/application/API that does not exist yet.
  • Test error conditions in a system not under our control.

  • TDD, unit tests
  • Spaghetti code
  • Simulate hard to replicate cases
  • 3rd party APIs or applications