EuroPython 2016

Managing Mocks

Mocking is a valuable technique for writing tests but mocking effectively is often a stumbling block for many developers and can raise questions about its overall value as a technique.

The audience will have some familiarity with unit testing and may have tried mocking before, but some introduction will be provided for those who haven’t. We will look at some features and techniques of Python’s unittest.mock library and cover some useful tips and common scenarios, so this will be useful to those who have some experience mocking but would like to do so more effectively.

Summary of proposed content:

  1. A short introduction to what mocking is and why it is useful.
  2. Tour of Python’s mock library and how to make the most of it
    • Creating and manipulating Mock objects
    • Setting up return values and side effects to control test environment
    • Inspecting mocks - different ways to examine a mock object and find out what happened during the test
    • How and where to patch
  3. Common mocking situations - scenarios where mocking is particularly useful and/or tricky to get right. For example - date/time, filesystem, read only properties
  4. Some discussion of when mocking is and isn’t helpful.

Focus will be mainly on Python’s unittest.mock module but we will also have a brief look at some other useful libraries.

in on Thursday 21 July at 15:45 See schedule

Do you have some questions on this talk?

New comment