python - Django pytest 断言错误 : should return body unicode

标签 python django pytest-django

我正在学习 django-pytest 并尝试测试 unicode,但出现错误

我的模型

class Post(models.Model):
    body = models.TextField()
    value = models.CharField(max_length=5)

    def __unicode__(self):
        return self.body

测试

class TestPost:
    def test_model(self):
        obj = mixer.blend('birdie.Post')
        assert obj.pk == 1, 'should create a post instance '

    def test_uniccode(self):
        obj = mixer.blend('birdie.Post',body='hello')
        result = obj.__unicode__
        assert result == 'hello', 'should return body unicode

我在测试 unicode 时遇到了困难,我这样做只是为了获得 100% 的覆盖率

错误 enter image description here

在通过测试时非常感谢任何帮助。提前致谢

最佳答案

object = obj
result = object.__unicode__()

关于python - Django pytest 断言错误 : should return body unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37992133/

相关文章:

python - 无法连接到我要上传文件的 dash 应用程序的服务器错误

python - 除了 ManyToMany 之外,是否有允许多种选择的 Django 模型字段?

python - 生产中的 Django 的 POST 请求在计算引擎上抛出服务器错误(500)

python - pytest 使用变量自省(introspection)断言消息自定义

django - 需要在 pytest 工厂中覆盖 django auto_now_add

python - 禁止从类外部使用默认构造函数

python - 我们如何根据订阅的主题消息的变化动态改变Tkinter标签小部件中的文本?

python - 在 Excel 中删除 Pandas 条件格式

python - 如何在 tastypie 中使用自定义用户类型限制 GET、POST 对资源的访问

python - 为什么pytest-django找不到manage.py?