thing = Thing.objects.create(name='1234')
# not sure if you need here .get() or if. create() truncates the field on its own
self.assertEqual(thing.name, '123') # or: self.assertEqual(len(thing.name), 3)
import unittest
from django.test import TestCase
class EmojiTestCase(TestCase):
@unittest.expectedFailure
def testCustomAssert(self):
self.assertHappyFace(':(') # must fail.
但是在测试过程中会打印一个警告消息。我和 Django 和 Nose 一起使用它。 其他人也看到了。