Description
Helen Sherwood-Taylor - Managing Mocks [EuroPython 2016] [21 July 2016] [Bilbao, Euskadi, Spain] (https://ep2016.europython.eu//conference/talks/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.
There will be a brief introduction to mocking, then a look at 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.
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:
A short introduction to what mocking is and why it is useful.
- 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
Common mocking situations - scenarios where mocking is particularly useful and/or tricky to get right. For example - date/time, filesystem, read only properties
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.