Introduce testing framework using pytest

While fixes like these are good, having them in the same commit as functional changes can make it a bit confusing to review. I had to stare at the one below for a little while before I figured out that it was just trailing whitespace.