How to test django model method __str__()

前端 未结 2 1416
眼角桃花
眼角桃花 2021-02-14 01:35

I trying to test __str__ method, and when trying to access it in my test it returns my model instance (I think it is)

def test_str_is_equal_to_title(self):
    \         


        
2条回答
  •  不知归路
    2021-02-14 02:21

    According to the documentation:

    Model.__str__()

    The __str__() method is called whenever you call str() on an object.

    You need to call str() on the model instance:

    self.assertEqual(str(work), work.title)
    

提交回复
热议问题