Side Effects of mock Module
Let’s discuss the implementation of side_effects.
We can also create side effects of mock objects via the
side_effect
argument. A side effect is something that happens when we run our function.
For example, some video games have integration into social media. When we score a certain number of points, win a
trophy, complete a level or some other predetermined goal, it will
record it and also post about it to Twitter, Facebook or whatever it is
integrated with. Another side effect of running a function is that it might be tied too closely with our user interface and cause it to redraw unnecessarily.
Since we know about these kinds of side effect up front, we can mock
them in our code. Let’s look at a simple example:
Get hands-on with 1200+ tech skills courses.