0

I'm trying to write integration tests with pybuilder on a Django web application, but I can't seem to make it work. An example error which occurs (from within the Django application):

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 is defined in build.py, like so:

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

The project is stored in src/main/python and integration tests are in src/integrationtest/python, like pybuilder's docs say it should be.

I've tried to manually set DJANGO_SETTINGS_MODULE in a lot of different places, including build.py and the test case itself. The same applies for settings.configure(). But it simply doesn't want to work and I don't know what I'm missing. I've ran out of ideas what to try.

morgoth84
  • 1,070
  • 2
  • 11
  • 25

1 Answers1

1

I've added os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") to the initialize function and I'm no longer getting this error.

Full build.py listing:

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")