Skip to content

Commit c74a007

Browse files
committed
A better way to manage test settings
1 parent fbb8af8 commit c74a007

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

tests/plugin_test.py

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,51 @@
1313
# Make Django templates outside of Django.
1414
# Originally taken from: http://stackoverflow.com/a/98178/14343
1515
from django.conf import settings
16-
test_settings = {
17-
'CACHES': {
18-
'default': {
19-
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
16+
17+
def test_settings():
18+
"""Create a dict full of default Django settings for the tests."""
19+
the_settings = {
20+
'CACHES': {
21+
'default': {
22+
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
23+
},
24+
},
25+
'DATABASES': {
26+
'default': {
27+
'ENGINE': 'django.db.backends.sqlite3',
28+
'NAME': ':memory:',
29+
}
2030
},
21-
},
22-
'DATABASES': {
23-
'default': {
24-
'ENGINE': 'django.db.backends.sqlite3',
25-
'NAME': ':memory:',
26-
}
27-
},
28-
'ROOT_URLCONF': 'tests',
29-
}
30-
31-
if django.VERSION >= (1, 8):
32-
test_settings.update({
33-
'TEMPLATES': [
34-
{
35-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
36-
'DIRS': ['templates'], # where the tests put things.
37-
'OPTIONS': {
38-
'debug': True,
31+
'ROOT_URLCONF': 'tests',
32+
}
33+
34+
if django.VERSION >= (1, 8):
35+
the_settings.update({
36+
'TEMPLATES': [
37+
{
38+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
39+
'DIRS': ['templates'], # where the tests put things.
40+
'OPTIONS': {
41+
'debug': True,
42+
},
3943
},
40-
},
41-
],
42-
})
44+
],
45+
})
46+
47+
if django.VERSION < (1, 10):
48+
# for {% ssi %}
49+
the_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/']
4350

44-
if django.VERSION < (1, 10):
45-
# for {% ssi %}
46-
test_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/']
51+
else:
52+
the_settings.update({
53+
'ALLOWED_INCLUDE_ROOTS': ['/'], # for {% ssi %}
54+
'TEMPLATE_DEBUG': True,
55+
'TEMPLATE_DIRS': ['templates'], # where the tests put things.
56+
})
4757

48-
else:
49-
test_settings.update({
50-
'ALLOWED_INCLUDE_ROOTS': ['/'], # for {% ssi %}
51-
'TEMPLATE_DEBUG': True,
52-
'TEMPLATE_DIRS': ['templates'], # where the tests put things.
53-
})
58+
return the_settings
5459

55-
settings.configure(**test_settings)
60+
settings.configure(**test_settings())
5661

5762
if hasattr(django, "setup"):
5863
django.setup()

tests/test_settings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
"""Settings tests for django_coverage_plugin."""
22

3-
import copy
4-
53
import django
64
from django.test.utils import override_settings
75

86
from django_coverage_plugin import DjangoTemplatePluginException
97

10-
from .plugin_test import DjangoPluginTestCase, test_settings
8+
from .plugin_test import DjangoPluginTestCase, test_settings, django_start_at
119

1210

1311
if django.VERSION >= (1, 8):
1412
DEBUG_FALSE_OVERRIDES = {
15-
'TEMPLATES': [copy.deepcopy(test_settings['TEMPLATES'][0])]
13+
'TEMPLATES': [test_settings()['TEMPLATES'][0]]
1614
}
1715
DEBUG_FALSE_OVERRIDES['TEMPLATES'][0]['OPTIONS']['debug'] = False
1816
else:

0 commit comments

Comments
 (0)