我在调试Django中unittest的代码方面遇到了一些问题 当我运行unittest时,我有输出
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
但是当我的同事进行同样的测试时,他得到了
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
正如您所看到的,第二个堆栈跟踪比我拥有的那个更高效。我可以更改设置(或安装某些内容)以扩展我的堆栈跟踪吗?
修改
操作系统:Ubuntu 11.04
Python:2.7.1
pdb已安装
答案 0 :(得分:1)
我不完全确定他收到的信息比你多。可能只是因为他的设置缺少一些模块或其他东西而导致更多的东西失败了。
你所看到的正是你应该看到的。这是一个失败,所以它在技术上不是你的单元测试中的错误,而是你的代码中正在测试的错误。传统的方法是编写测试,观察测试失败,然后编写功能,并观察它的通过。如果您发现自己正在调试测试,那么这种做法就会失败。