Specific asserts versus generic asserts
One question that might come to your mind is why there are so many different assert methods. Why can't we just use assertTrue
instead of the more specific assert, as shown in the following code:
assertInSeq(x, seq) assertTrue(x in seq) assertEqual(10, x) assertTrue(x == 10)
While they are certainly equivalent, one motivation for using a specific assert is that you get a better error message if the assertion fails. When comparing objects like lists and dicts, the error message will show exactly where the difference occurs, making it much easier to understand. Therefore, it is recommended to use the more specific asserts wherever possible.