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
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Getting started with nose2


Installing nose2 is a breeze. The easiest way to install it is via pip with the following command:

pip install nose2

Let us now run our tests using nose2. From the stock alerter project directory, run the nose2 command (we might have to add it to the path first). nose2 has test autodiscovery by default, so just running the command should give the following output:

...............................................................
----------------------------------------------------------------------
Ran 63 tests in 0.109s

OK

As we can see, the nose2 command gives the same output as unittest. nose2 which also discovered the same tests and ran them. By default, nose2 autodiscover patterns are compatible with unittest, so we can just drop in nose2 as a replacement runner without changing any code.