Contribute Media
A thank you to everyone who makes this possible: Read More

Mocking: virtual reality for your Python tests


Unit tests: they are fast, easy to write and protect your code against future bugs. But what happens when unit tests depend on modules you don't want to test? Or even when they depend on external APIs you cannot use while testing? That's where mocking comes in. The unittest.mock module lets you mimic behavior for your test dependencies. It also gives you tools to make sure your code calls its dependencies at the right places and with the right arguments.

This talk will use a set of examples to showcase what the mock module can do, and how to make use of it in your tests. We will cover mocking functions, objects and modules, as well as various caveats and recipes for mocking Python code.


Improve this page