Module 6: Testing Our Code

This module will introduce us to the critically-important and often-overlooked process of testing code. We will begin by considering some general motivations for writing tests. Next, we will study the basic anatomy of a test-function, including the assert statement, which serves as the nucleus of our test functions. Armed with the ability to write a rudimentary test, we will welcome, with open arms, the powerful testing framework pytest. This will inform how we structure our tests alongside our Python project; with pytest, we can incisively run our tests with the press of a single button. Furthermore, it will allow us to greatly streamline and even begin to automate some of our tests. Finally, we will take a step back to consider some strategies for writing effective tests. Among these is a methodology that is near and dear to my heart: property-based testing. This will take us down a bit of a rabbit hole, where we will find the powerful property-based testing library Hypothesis waiting to greet us (adorned with the mad Hatter’s cap and all).