[Fixed]-How to test django model method __str__()

36👍

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)
👤alecxe

4👍

Alternatively, you may simply call it like:

model_instance.__str__()

Leave a comment