Book Image

Test-Driven Python Development

By : Siddharta Govindaraj
Book Image

Test-Driven Python Development

By: Siddharta Govindaraj

Overview of this book

This book starts with a look at the test-driven development process, and how it is different from the traditional way of writing code. All the concepts are presented in the context of a real application that is developed in a step-by-step manner over the course of the book. While exploring the common types of smelly code, we will go back into our example project and clean up the smells that we find. Additionally, we will use mocking to implement the parts of our example project that depend on other systems. Towards the end of the book, we'll take a look at the most common patterns and anti-patterns associated with test-driven development, including integration of test results into the development process.
Table of Contents (20 chapters)
Test-Driven Python Development
About the Author
About the Reviewers

Appendix B. Working with Older Python Versions

This book has been written for Python 3.4. The version of unittest that comes with the Python 2.x standard library is an older version that doesn't support all the features that we discussed in this book. Additionally, the mock library was only made a part of the standard library from Python 3.3 onward.

Fortunately, all the features present in the newer versions of Python have been backported under the unittest2 library. We can install this version from PyPi with the following command:

pip install unittest2

Once installed, we have to use the unittest2 library in all references like the following:

import unittest2

class StockTest(unittest2.TestCase):

With these changes, we will be able to use all the features that we have been discussing in this book in all versions from Python 2.5 onward.

The same goes for the mocking library as well. The mock library was only added to the standard library with Python 3.3. The current mock library has been backported and is also available from PyPi. We can install it with the following command:

pip install mock

And we import it with the following command:

import mock

We can then use all the mocking goodness discussed in this book with earlier versions of Python as well.