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:
nosetests
doctests
and running themWe need to activate our virtual environment (virtualenv) and then install nose for this recipe.
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.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
.nosetests –with-doctest
against both the recipe19.py
file as well as the recipe19
module, in different combinations.
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.
Getting nosy with testing section mentioned in Chapter 2
3.22.61.218