Running tests from the command line
Throughout the book, we have used the following syntax to run our tests:
python.exe -m unittest
The ability to directly run a module with the -m
flag was only introduced with Python 2.7. This syntax will not work if we are using an older version of Python. Instead, the unittest2
module from PyPi contains a unit2
script that mimics this behavior. The command line parameters remain the same, so we get the following the command:
python3 -m unittest discover -s stock_alerter -t .
And the above command now becomes:
unit2 discover -s stock_alerter -t .
If we use a build tool, it becomes fairly simple to check the version of Python and execute the appropriate command, thereby allowing the developer to run the tests in a uniform way, irrespective of the Python version being used.
With these changes in place, we will be able to use all the features described in this book, while being able to support Python 2.x and Python 3.x uniformly.