We throw lots of ValueErrors and TypeErrors rather than creating new exception types all over the place. There's definitely an argument to be made that different exception types can be created. But I know that I've definitely run afoul of believing I was testing one error (assertRaises) when I wasn't. A different ValueError was being caught and the test was incorrectly passing. I would prefer assertRaises[Message|Regex] for verifying the location of the error (not the exact string) where it makes sense, and a simple assertRaises where the behaviour is immediately clear.
On Friday, 7 April 2017 22:18:30 UTC+10, Shai Berger wrote: > > Hi Tim, > > > Without testing for a message, there's also a possibility that the > > exception you think you're testing isn't the one the test is actually > > raising. > > If you need to verify the error message for that reason, then the > exception is > probably not specific enough. Testing the message, in this case, is just > working around faulty design. > > > I think the readability advantages of including messages in the > > tests outweigh the cost of updating tests when a message changes. > > In some cases, of course; but I see a significant distance between that > and a > general recommendation to prefer assertRaisesMessage. > > Shai. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/296c301e-3a3d-462a-90fc-b54d2a1ca70f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.