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.