【问题标题】:Pybuilder integration tests on a Django projectPybuilder 对 Django 项目的集成测试
【发布时间】:2015-02-11 15:15:18
【问题描述】:

我正在尝试在 Django Web 应用程序上使用 pybuilder 编写集成测试,但我似乎无法使其工作。发生的示例错误(来自 Django 应用程序):

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

DJANGO_SETTINGS_MODULE build.py中定义的,像这样:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")

项目存储在src/main/python,集成测试存储在src/integrationtest/python,就像pybuilder的文档说的那样。

我尝试在很多不同的地方手动设置DJANGO_SETTINGS_MODULE,包括build.py 和测试用例本身。这同样适用于settings.configure()。但它根本不想工作,我不知道我错过了什么。我已经想不出要尝试什么了。

【问题讨论】:

    标签: python django python-2.7 integration-testing pybuilder


    【解决方案1】:

    我已将os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") 添加到initialize 函数中,并且不再出现此错误。

    完整的 build.py 清单:

    from pybuilder.core import init, use_plugin
    import os
    
    use_plugin("python.core")
    use_plugin("python.unittest")
    use_plugin("python.django")
    
    default_task = "publish"
    
    
    @init
    def initialize():
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
    

    【讨论】:

      猜你喜欢
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 2013-08-06
      • 1970-01-01
      • 1970-01-01
      • 2023-01-23
      相关资源
      最近更新 更多