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.
pip install unittest2
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:
We can then use all the mocking goodness discussed in this book with earlier versions of Python as well.