Currently, I am creating a test script. but I am getting this error:
<bound method Score.percentage of <Score: Score object>> != 100
these are my codes:
models.py
class Score(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Name = models.CharField(max_length=120)
score = models.FloatField(null=True, default=0)
def percentage(self):
percentage = (score/50) * 100
return percentage
This is my test script (test.py)
self.assertEqual(Score.percentage, 100)
I am expecting:
Score.percentage = 100
but I got
<bound method Score.percentage of <Score: Score object>> != 100
Percentage is a method so you need to call it
self.assertEqual(Score.percentage, 100)
should be
self.assertEqual(Score.percentage(), 100)
Note: it still won't work correctly though since you need to call the method on an instance of score, and call the instances score ( self.score
) inside of the method instead of score.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.