dasm
dasm

Reputation: 192

Debugging unittests

I have some problems with debugging code from unittest in Django.
While I run unittest, I have output

FAIL: test_basket (api.api_1_0.tests.basket_tests.BasketTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dasm/apps/filmaster/reloaded/film20/api/api_1_0/tests/basket_tests.py", line 13, in test_basket
    self.assertEquals(status, 200)
AssertionError: 400 != 200

but when my colleague run the same test, he get

2011-06-10 14:58:33,221 - WARNING:notification.models - No module named APNSWrapper - @<module>/96
/home/michuk/djcode/filmaster-reloaded/piston/handler.py:36: UserWarning: Handler already registered for model ChannelScreenings, you may experience inconsistent results.
  "you may experience inconsistent results." % new_cls.model.__name__)
2011-06-10 14:58:33,844 - ERROR:film20.api.api_1_0.handlers - extra() got an unexpected keyword argument 'join' - @error_handler/93
Traceback (most recent call last):
  File "/home/michuk/djcode/filmaster-reloaded/piston/resource.py", line 164, in __call__
    result = meth(request, *args, **kwargs)
  File "/home/michuk/djcode/filmaster-reloaded/film20/api/api_1_0/handlers.py", line 161, in wrapper
    return view(self, request, request.username, *args, **kw)
  File "/home/michuk/djcode/filmaster-reloaded/film20/api/api_1_0/handlers.py", line 1051, in read
    return paginated_collection(request, BasketItem.objects.user_items(username, type).select_related('user', 'film'))
  File "/home/michuk/djcode/filmaster-reloaded/film20/filmbasket/models.py", line 67, in user_items
    join=['LEFT OUTER JOIN "core_recommendation" ON ("filmbasket_basketitem"."film_id" = "core_recommendation"."film_id" and "filmbasket_basketitem"."user_id" = "core_recommendation"."user_id")'],
TypeError: extra() got an unexpected keyword argument 'join'

Failure
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/django/utils/unittest/case.py", line 339, in run
    testMethod()
  File "/home/michuk/djcode/filmaster-reloaded/film20/api/api_1_0/tests/basket_tests.py", line 15, in test_basket
    self.assertEquals(status, 200)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/unittest/case.py", line 520, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/unittest/case.py", line 513, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 400 != 200

As you can see, second stacktrace is much more efficient from that one, which I have. Can I change my settings (or install something) to expand my stacktrace?

edit:
OS: Ubuntu 11.04
Python: 2.7.1
pdb installed

Upvotes: 3

Views: 734

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239460

I'm not entirely sure he's getting more info than you. It might be simply that more stuff is failing for him, due to some missing modules or something on his setup.

What you're seeing is exactly what you should be seeing. It's a failure, so it's not technically a bug in your unittest but rather a bug in your code that's being tested. The traditional methodology is to write the test, watch it fail, then write the feature, and watch it pass. If you're find yourself debugging your tests, that kind of defeats the point of the exercise.

Upvotes: 1

Related Questions