O'Reilly logo

Python Testing Cookbook by Greg L. Turnquist

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

Writing a testable story with Voidspace Mock and nose

When our code interacts with other classes through methods and attributes, these are referred to as collaborators. Mocking out collaborators using Voidspace Mock (http://www.voidspace.org.uk/python/mock, created by Michael Foord) provides a key tool for BDD. Mocks provide a way for provided canned behavior compared to stubs, which provide canned state. While mocks by themselves don't define BDD, their usage keenly overlaps the ideas of BDD.

To further demonstrate the behavioral nature of the tests, we will also use the spec nose plugin found in the Pinocchio project (http://darcs.idyll.org/~t/projects/pinocchio/doc).

Note

As stated on the project's website, Voidspace Mock is experimental. This ...

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