Getting nosy with doctest

Up to this point, we have been either appending modules with a test runner, or we have typed python -m doctest <module> on the command line to exercise our tests.

In the previous chapter, we introduced the powerful library nose (refer to http://somethingaboutorange.com/mrl/projects/nose for more details).

For a quick recap, nose:

  • Provides us with the convenient test discovering tool nosetests
  • Is pluggable, with a huge ecosystem of available plugins
  • Includes a built-in plugin targeted at finding doctests and running them

Getting ready

We need to activate our virtual environment (virtualenv) and then install nose for this recipe.

  1. Create a virtual environment, activate it, and verify the tools are working.
    Getting ready
  2. Using pip, install nose.
    Getting ready

    Note

    This recipe assumes you have built all of the previous recipes in this chapter. If you have built only some of them, your results may appear different.

How to do it...

  1. Run nosetests –with-doctest against all the modules in this folder. If you notice, it prints a very short .....F.F...F, indicating that three tests have failed.
  2. Run nosetests –with-doctest -v to get a more verbose output. In the following screenshot, notice how the tests that failed are the same ones that failed for the previous recipes in this chapter. It is also valuable to see the <module>.<method> format with either ok or FAIL.
    How to do it...
  3. Run nosetests –with-doctest against both the recipe19.py file as well as the recipe19 module, in different combinations.
    How to do it...

How it works...

nosetests is targeted at discovering test cases and then running them. With this plugin, when it finds a docstring, it uses the doctest library to programmatically test it.

The doctest plugin is built around the assumption that doctests are not in the same package as other tests, like unittest. This means it will only run doctests found from non-test packages.

There isn't a whole lot of complexity in the nosetests tool, and...that's the idea!. In this recipe, we have seen how to use nosetests to get a hold of all the doctests we have built so far in this chapter.

See also

Getting nosy with testing section mentioned in Chapter 2

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.61.218