O'Reilly logo

Python Testing Beginner's Guide by Daniel Arbuckle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Breaking Tight Coupling by using Mock Objects

Several times in the previous chapters, we've run across cases where we needed to go out of our way to make sure that units didn't contaminate each others' tests. Now we're going to look at a formalization of how to handle those situations—mock objects—and also at a specific mock object toolkit called Python Mocker.

In this chapter, we shall:

  • Examine the ideas of mock objects in general
  • Learn how to use Python Mocker
  • Learn how to mock the "self" parameter of a method

So let's get on with it!

Installing Python Mocker

For the first time, we're using a tool that isn't included in the standard Python distribution. That means that we need to download and install it.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required