0

So, I have a test that looks like this:

 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

The weird part is that if I run the test and at the breakpoint I just hit c (continue), it fails the test:

/home/alejandro/Proyectos/misuper_env/misuper_project/app/misuper/tests.py(1162)test_retailers_categories()

-> pdb.set_trace()

(Pdb) c

FAIL ...

AssertionError: Bebidas not in []

But if in the breakpoint I write category_name and response_category_names just to print them, the test passes correctly.

(Pdb) category_name

u'Bebidas'

(Pdb) response_category_names

[u'Bebidas']

(Pdb) c

ok

Why??

Alejandro Veintimilla
  • 10,743
  • 23
  • 91
  • 180

1 Answers1

0

The test has category_name in not_empty_categories, not response_category_names. I believe the not_empty_categories here is empty.

masnun
  • 11,635
  • 4
  • 39
  • 50