Introduction to Mocking in Python
Prashanth Pai (~prashanthpai) |
mock is a Python testing module that allows you to replace parts (methods, classes etc) of your application with mock objects and make assertions about how they have been used. This talk nicely compliments "Unit testing 101" talk if such a talk has been proposed by someone else.
This talk aims to primarily touch upon the following topics:
- What is NOT a unit test ?
- Why do you need mocking ?
- Monkey Patching
- Where, why and what to patch
- Mocking network calls and I/O
Also illustrate examples of real code that use the above techniques. Among the things that I certainly do not wish to talk about is compare various mocking libraries. For example mock vs mox ;)
- Basic understanding of exception handling, magic methods, decorators etc.
- Very basic understanding of unit testing in Python
Knowing unittest and nose modules is a plus but not a pre-requisite per se.
Prashanth Pai works as Associate Software Engineer at Red Hat. He is primarily associated with and contributes to the following open source projects: