Doctest and unittest... now they'll be merrily together


Testing is a very important discipline to ensure and validate software quality. Python includes two standard modules to perform functional testing. Prior to version 2.4 both tools were unrelated, leading to scattered testing code. From this version on a unittest API is provided by doctest. The present work aims to propose some enhancements to this API in order to achieve a better unittest-doctest integration. Although there are more complex testing tools (e.g. nose) which allow performing both kinds of tests, they are outside the scope of this article. Firstly, they are not standard modules. Besides, the intent is to load and execute doctests just like if we were using unittest.

Even though many types of tests exist these days1, functional testing is very important. Firstly, it validates whether software behavior matches the business rules documented in the software requirements. Besides, for continuously evolving systems and iterative development processes it is also crucial to perform regression testing. Thereby introduced defects are handled as soon as possible and the defect does not propagate to future versions. These tests are also the main building block for test-driven development and extreme programming techniques. A scripting language like Python ought to be aware of this since it is often used to write test scripts (e.g. for Java2 and .NET3). Because of this, the paper also covers the standard modules available nowadays in Python for functional testing.

Full Text: