Testing modules and packages
Testing is a normal part of programming: you test your code to verify that it works and identify any bugs or other problems, which you can then fix. Then, you test some more, until you are happy that your code is working correctly.
All too often, however, programmers just do
ad hoc testing: they fire up the Python interactive interpreter, import their module or package, and make various calls to see what happens. In the previous chapter, we looked at a form of ad hoc testing using the importlib.reload()
function to support RAD development of your code.
Ad hoc testing is useful, but it isn't the only form of testing. If you are sharing your modules and packages with others, you will want your code to be bug-free, and ad-hoc testing can't guarantee this. A much better and more systematic approach is to create a series of unit tests for your module or package. Unit tests are snippets of Python code which test various aspects of your code. Because the testing is done...