On 23 December 2010 17:56, Ian Clelland <clell...@gmail.com> wrote: > On Thu, Dec 23, 2010 at 8:46 AM, Karen Tracey <kmtra...@gmail.com> wrote: >> On Thu, Dec 23, 2010 at 8:44 AM, Luke Plant <l.plant...@cantab.net> wrote: >> Perhaps it is not a problem when using bare asserts for this purpose, but I >> have grown to dislike asserts in testcases because they give so little >> information. For example, I am working with test code that uses bare asserts >> all over the place instead of the TestCase methods and when these tests fail >> I get errors like this: >> >> Traceback (most recent call last): >> File [snipped] >> assert res.status_code == 200 >> AssertionError >> >> Well, great, status wasn't 200 but what was it? That's information I'd >> really rather get by default, so I much prefer assertEquals, which tells me: >> >> Traceback (most recent call last): >> File [snipped] >> self.assertEqual(res.status_code, 202) >> AssertionError: 302 != 200 >> >> That actually gives me enough information that I might be able to fix the >> problem straight off. >> >> Do you not find the paucity of information provided by bare assert to be >> annoying? > > Test cases should probably be using the two-argument form of assert: > > assert (res.status_code == 200), "The status code returned was incorrect" > > or even > > assert (res.status_code == 200), ("%s != 200" % res.status_code)
Now imagine you have to do that 20 times using different operators ( ==, <, >, is, in). The second thing is exactly what assertEqual() does (at least for integers), so why duplicate it ? OTOH, it's a shame unittest doesn't let you add a message prefix (at least I couldn't find it), only replaces the default. -- Łukasz Rekucki -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.