Django 1.4 - assertQuerysetEqual - how to use method

后端 未结 2 1476
庸人自扰
庸人自扰 2020-12-08 15:04

I\'m wondering how the TestCase.assertQuerysetEqual method works. I tried it in different ways, each of them leading me to another error message.

#create a b         


        
相关标签:
2条回答
  • 2020-12-08 15:49

    try this:

    self.assertQuerysetEqual(
        tree_record_qs,
        [repr(r) for r in tree_record_backup]
    )
    

    it's a bit weird and undocumented; but, that should work for you.

    0 讨论(0)
  • 2020-12-08 16:03

    assertQuerysetEqual takes a queryset, a list of values and a transform callable which is called on the queryset to convert it into something comparable to the list of values. By default this callable is repr. This is kind of irritating since it doesn't actually compare two querysets, but the easy fix for most cases is using map(repr, your_second_queryset) for the list of values. This is documented in django since version 1.3.

    0 讨论(0)
提交回复
热议问题