Search⌘ K

Diving In

Explore how to identify and reproduce bugs by writing failing test cases before fixing the code. Understand effective refactoring practices including handling exceptions and using Python 3's improved string formatting. Learn how test-driven development helps ensure bug fixes are reliable and prevent regression.

We'll cover the following...

Like it or not, bugs happen. Despite your best efforts to write comprehensive unit tests, bugs happen. What do I mean by “bug”? A bug is a test case you haven’t written yet.

Python 3.5
import roman7
print (roman7.from_roman('')) #①
#0

① This is a bug. An empty string should raise an InvalidRomanNumeralError exception, just like any other sequence of characters that don’t represent a valid Roman numeral.

After reproducing the bug, and before fixing it, you should write a test case that fails, thus ...