【问题标题】:When i execute unittest command "python3 -m unittest filepath/filename.py" it showing improperly configured error当我执行 unittest 命令“python3 -m unittest filepath/filename.py”时,它显示配置错误
【发布时间】:2021-01-27 08:45:52
【问题描述】:

当我执行单元测试命令:python3 -m unittest filepath/filename.py 时,它会抛出一个配置不正确的错误,谁能帮助解决这个问题,不胜感激

错误:

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but 
settings are not configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

【问题讨论】:

  • 如果您运行python -m django unittestfilepath/filename.py,它应该可以工作,因为当您将django 作为子命令运行时,环境变量已设置

标签: python python-3.x django unit-testing


【解决方案1】:

您需要设置运行单元测试所需的设置文件。

在 Linux 上

$ export DJANGO_SETTINGS_MODULE=your_setting

请阅读https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#testing-other-python-versions-and-database-backends

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 2019-08-24
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 2014-07-05
    相关资源
    最近更新 更多