django - Django Unittest遇到错误

标签 django python-3.x sqlite django-unittest

环境:
Intellij PyCharm,Python Django,Sqlite3

我使用标准的Django安装项目。
我尝试编写一些单元测试,但是遇到以下错误。
经过研究,我最终来到了这里。

数据库配置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


tests.py代码

from django.test import TestCase as djangoTestCase
import os
import unittest

# Create your tests here.
class TestExample(djangoTestCase):

    def setUp(self):
        print('setup')
        print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

    def test_abc(self):
        self.assertEqual(1,1)

    def tearDown(self):
        print('tearDown')

if __name__ == '__main__':
    unittest.main()


这是输出

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.


我试图通过阅读文档来查找错误,但是没有成功。
可能是什么问题呢?

最佳答案

使用Django测试,您不需要这部分:

if __name__ == '__main__':
    unittest.main()


您只需使用python manage.py test命令运行测试。

关于django - Django Unittest遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48020116/

相关文章:

django admin "add page"来自 GET 参数的初始日期时间

django - 如何使Django表单中的ChoiceField只读

python - 如何在打印语句后取消换行符?

c# - 使用 C# 连接到 SQLite

android - 如何在 android 中将游标对象转换为 XML 或 JSON

python - 在 Django 1.7 中启动时执行代码

python - kombu.exceptions.EncodeError : User is not JSON serializable 错误

Python:如何将我获得的随机输出量限制为特定数量?

python-3.x - git clone fatal error - 存储库 'https' 不存在

sqlite3_analyzer 在缺少共享对象文件的 Ubuntu 中不工作