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

nose2 plugins

In the previous section, we saw how we needed to enable the Layers plugin before we could run our layer tests. nose2 comes with a large set of plugins that enhance or extend its behavior. In fact, support for all the parameterized tests and generated tests that we saw earlier are actually implemented as nose2 plugins. The difference is that parameterized and generated tests are loaded by default, so we didn't need to explicitly enable them.

In this section, we'll take a look at some of the popular plugins. Keep in mind that there are many more plugins that we aren't going to discuss here.

Doctest support

If we have not integrated doctests into the unittest framework as described in the previous chapter, then we can configure nose2 to autodiscover and run doctests.

Activate the plugin with the following command:

nose2 --plugin nose2.plugins.doctests --with-doctest

This will autodiscover and run doctests along with all the other kinds of tests.

Writing test results to an XML file