Skip to content

Commit

Permalink
Wrap django config/setup in a function, call at the beginning of main…
Browse files Browse the repository at this point in the history
… block.
  • Loading branch information
weswil07 committed Oct 19, 2023
1 parent aa4cda0 commit 23ed523
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,40 +1754,43 @@ def rel_path(*p):
rel_path.path = osp.abspath(osp.dirname(__file__))
this = osp.splitext(osp.basename(__file__))[0]

from django.conf import settings
SETTINGS = dict(
SITE_ID=1,
DATABASES = {
'default':{
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'daffodil_hstore_test',
'USER': "postgres",
'PASSWORD': "postgres",
'HOST': '127.0.0.1',
'PORT': 5432,
}
},
DEBUG=True,
TEMPLATE_DEBUG=True,
INSTALLED_APPS=[
"django.contrib.postgres",
"testapp",
],
ROOT_URLCONF=this,
MIDDLEWARE_CLASSES=(),
)

print("DOES THIS LINE GET CALLED?!")
def engage_django_setup():
from django.conf import settings
import django
from traceback import print_exc
SETTINGS = dict(
SITE_ID=1,
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'daffodil_hstore_test',
'USER': "postgres",
'PASSWORD': "postgres",
'HOST': '127.0.0.1',
'PORT': 5432,
}
},
DEBUG=True,
TEMPLATE_DEBUG=True,
INSTALLED_APPS=[
"django.contrib.postgres",
"testapp",
],
ROOT_URLCONF=this,
MIDDLEWARE_CLASSES=(),
)

if not settings.configured:
settings.configure(**SETTINGS)

try:
django.setup()
except AttributeError:
print_exc()

if not settings.configured:
settings.configure(**SETTINGS)

import django
from traceback import print_exc
try:
django.setup()
except AttributeError:
print_exc()
engage_django_setup()


from daffodil.hstore_predicate import HStoreQueryDelegate
Expand All @@ -1811,6 +1814,7 @@ def test_none(self):
from django.core import management

if __name__ == "__main__":
engage_django_setup()
management.call_command("migrate")

BasicHStoreData.objects.all().delete()
Expand Down

0 comments on commit 23ed523

Please sign in to comment.