Only import gis test apps for geo-enabled DBs

This commit is contained in:
Claude Paroz 2013-07-09 15:58:56 +02:00
parent bd563f0f57
commit 57f190ed3b
1 changed files with 10 additions and 5 deletions

View File

@ -12,13 +12,11 @@ from django.utils._os import upath
from django.utils import six from django.utils import six
CONTRIB_MODULE_PATH = 'django.contrib' CONTRIB_MODULE_PATH = 'django.contrib'
CONTRIB_GIS_TESTS_PATH = 'django.contrib.gis.tests'
TEST_TEMPLATE_DIR = 'templates' TEST_TEMPLATE_DIR = 'templates'
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__))) RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
CONTRIB_DIR = os.path.dirname(upath(contrib.__file__)) CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
CONTRIB_GIS_TESTS_DIR = os.path.join(CONTRIB_DIR, 'gis', 'tests')
TEMP_DIR = tempfile.mkdtemp(prefix='django_') TEMP_DIR = tempfile.mkdtemp(prefix='django_')
os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR
@ -52,11 +50,18 @@ ALWAYS_INSTALLED_APPS = [
def get_test_modules(): def get_test_modules():
from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
modules = [] modules = []
for modpath, dirpath in ( discovery_paths = [
(None, RUNTESTS_DIR), (None, RUNTESTS_DIR),
(CONTRIB_MODULE_PATH, CONTRIB_DIR), (CONTRIB_MODULE_PATH, CONTRIB_DIR)
(CONTRIB_GIS_TESTS_PATH, CONTRIB_GIS_TESTS_DIR)): ]
if HAS_SPATIAL_DB:
discovery_paths.append(
('django.contrib.gis.tests', os.path.join(CONTRIB_DIR, 'gis', 'tests'))
)
for modpath, dirpath in discovery_paths:
for f in os.listdir(dirpath): for f in os.listdir(dirpath):
if ('.' in f or if ('.' in f or
# Python 3 byte code dirs (PEP 3147) # Python 3 byte code dirs (PEP 3147)