所以,我有一个看起来像这样的测试:
for retailer in Retailer.objects.all():
retailer_categories = retailer.categories.all()
empty_categories = []
not_empty_categories = []
for category in retailer_categories:
if StockItem.objects.filter(retailer=retailer, product__category=category).exists():
not_empty_categories.append(category.name)
else:
empty_categories.append(category.name)
response = self.client.get(reverse("misuper:retailer_categories", kwargs={"id": retailer.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_category_names = [c["name"] for c in response.json()]
for category_name in response_category_names:
pdb.set_trace() # HERE
self.assertEqual(category_name in not_empty_categories, True, "%s not in %s" % (category_name, not_empty_categories)) # THIS TEST
奇怪的是,如果我运行测试并且在断点处我只是点击c
(继续),它就会通过测试:
/home/alejandro/Proyectos/misuper_env/misuper_project/app/misuper/tests.py(1162)test_retailers_categories()
- > pdb.set_trace()
(Pdb)c
失败......
AssertionError:Bebidas不在[]
中
但是如果在断点中我写category_name
和response_category_names
只是为了打印它们,那么测试就会正确传递。
(Pdb)category_name
U' BEBIDAS'
(Pdb)response_category_names
[U' BEBIDAS']
(Pdb)c
确定
为什么?
答案 0 :(得分:0)
测试有category_name in not_empty_categories
,而不是response_category_names
。我相信这里的not_empty_categories
是空的。