Breaking down obscure tests into simple ones

Unittest provides the means to test the code through a series of assertions. I have often felt the temptation to exercise many aspects of a particular piece of code within a single test method. If any part fails, it becomes obscured as to which part failed. It is preferable to split things up into several smaller test methods, so that when some part of the code under test fails, it is obvious.

How to do it...

With these steps, we will investigate what happens when we put too much into a single test method.

  1. Create a new file named in which to put our application code for this recipe.
  2. Pick a class to test. In this case, we will use an alternative version of the Roman numeral converter, which converts ...

Get Python Testing Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.