In the previous chapter, we saw various approaches to metaprogramming and programmable syntax in Python. In this chapter, we're going to take a look at the ideas behind unit testing, then move on to several test automation tools we can use to make our testing easier and more useful. We'll focus on what unit testing is, and the ideas that motivate it. We'll also discuss Python's standard unittest package and how it works.
Finally, you'll learn how to use unittest.mock to control the environment that your test code will run in so that the test will remain focused on making sure one thing works properly.
In this chapter, we'll cover the following topics:
- Understanding the principle of unit testing
- Using the unittest package
- Using unittest.mock
- Using unittest's test discovery
- Using nose for unified test discovery and reporting