Skip to content

Commit 43bc9fe

Browse files
author
Pamela McA'Nulty
committed
Don’t check settings until it’s been configured
1 parent 6ca6525 commit 43bc9fe

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

django_coverage_plugin/plugin.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def check_debug():
4343
to do its work. Check that the setting is correct, and raise an exception
4444
if it is not.
4545
46+
Returns True if the debug check was performed, False otherwise
4647
"""
4748
# The settings for templates changed in Django 1.8 from TEMPLATE_DEBUG to
4849
# TEMPLATES[..]['debug']. Django 1.9 tolerated both forms, 1.10 insists on
@@ -51,14 +52,17 @@ def check_debug():
5152

5253
from django.conf import settings
5354

55+
if not settings.configured:
56+
return False
57+
5458
try:
5559
templates = getattr(settings, 'TEMPLATES', [])
5660
except ImproperlyConfigured:
5761
# Maybe there are no settings at all. We are fine with this. Our
5862
# code will need settings, but if this program we're in runs without
5963
# settings, then it must be that it never uses templates, and our code
6064
# will never try to use the settings anyway.
61-
return
65+
return True
6266

6367
if templates:
6468
for template_settings in templates:
@@ -75,6 +79,8 @@ def check_debug():
7579
"Template debugging must be enabled in settings."
7680
)
7781

82+
return True
83+
7884

7985
if django.VERSION >= (1, 9):
8086
# Since we are grabbing at internal details, we have to adapt as they
@@ -151,8 +157,7 @@ def sys_info(self):
151157
def file_tracer(self, filename):
152158
if filename.startswith(self.django_template_dir):
153159
if not self.debug_checked:
154-
check_debug()
155-
self.debug_checked = True
160+
self.debug_checked = check_debug()
156161

157162
return self
158163
return None

0 commit comments

Comments
 (0)