Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django写作测试_Django_Testing - Fatal编程技术网

Django写作测试

Django写作测试,django,testing,Django,Testing,我为Django编写了一个小测试。它总是返回不正确的true。代码附在下面。我不明白为什么?谢谢你的帮助 from django.tests import TestCase from myapp.models import Content class SimpleTest(TestCase): def test_add_user(self): cnt = Content('en', 'hello world!') cnt.save()

我为Django编写了一个小测试。它总是返回不正确的true。代码附在下面。我不明白为什么?谢谢你的帮助

from django.tests import TestCase
from myapp.models import Content


class SimpleTest(TestCase):
    def test_add_user(self):
        cnt = Content('en', 'hello world!')
        cnt.save()
        self.assertEqual(cnt.text, 'hello world again!')
我通过在myapp/下创建一个tests/文件夹来实现它。然后我将test.py移动到myapp/tests/,我还将
\uuuu init\uuuu.py
放在同一个文件夹中。然后它就起作用了


谢谢。

您如何定义您的
内容
模型?您的代码不正确<代码>django.tests
不是django的模块之一。