EuroPython 2018

Mocks, fakes, dummies, stubs and spies: Successfully isolating the snake

Speaker(s) Mario Corchero

Ever wonder what mocks, fakes, dummies stubs or spies are? Or what the differences are between them and when one should be used instead of another? We will take a deep look into these concepts, what they mean and examples on how to use/create them in Python.

In this talk, we will quickly explore the reasons for using mock and how it works, quickly jumping into the different concepts of testing doubles and how they can be used in Python. The talk will include as part of the examples from some features in mock coming in Python 3.7 that might change how usual mocking is performed. The talk builds on the writings of Gerard Meszaros and Martin Fowler about testing doubles, focusing on how to apply them to Python.

This session, which will review test isolation concepts and the unittest.mock module, is structured in a way that both beginners and intermediate developers will learn from it. A basic knowledge of testing is recommended. Intermediate developers will leave the room with a clear understanding of the tools - further than just using simple mocks - to successfully fake dependencies. Multiple “not so well known” features of unittest.mock will be presented so we can shape those objects to behave functionally different. Unittest.mock is an extremely useful library which is commonly underused, this talk aims to bring clarity into stubbing in general and into medium/advanced mock features to ease and remove pain when users work with it.


• Intro (1’) • Why doubles are important (1’) • Main qualities of a double (2’) • Overview of unittest.mock (5’) • Testing doubles (15’) o Doubles (1’) o Stubs (2’) o Spies (3’) o Mocks (5’) o Fakes (2’) • Wrap up, conclusion and pointers (2’) • Q&A (Expected 5’)

in on Thursday 26 July at 14:35 See schedule

Do you have some questions on this talk?

New comment