On Thu, Dec 23, 2010 at 8:44 AM, Luke Plant <l.plant...@cantab.net> wrote:

> Hi all,
>
> This is a question of test code style.
>
> In tests in my own projects, I use both the Python 'assert' statement
> and the unittest TestCase.assert* methods, with the following
> distinction:
>
> * The 'assert' statement is used to make assertions about the
> assumptions built in to *this* bit of code (i.e. the test itself).
>

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?

Karen

-- 
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.

Reply via email to