Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only import gis test apps for geo-enabled DBs

  • Loading branch information...
commit 57f190ed3b77eb105cc86ecfabc455662410d40a 1 parent bd563f0
@claudep claudep authored
Showing with 10 additions and 5 deletions.
  1. +10 −5 tests/runtests.py
View
15 tests/runtests.py
@@ -12,13 +12,11 @@
from django.utils import six
CONTRIB_MODULE_PATH = 'django.contrib'
-CONTRIB_GIS_TESTS_PATH = 'django.contrib.gis.tests'
TEST_TEMPLATE_DIR = 'templates'
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__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_')
os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR
@@ -52,11 +50,18 @@
def get_test_modules():
+ from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
modules = []
- for modpath, dirpath in (
+ discovery_paths = [
(None, RUNTESTS_DIR),
- (CONTRIB_MODULE_PATH, CONTRIB_DIR),
- (CONTRIB_GIS_TESTS_PATH, CONTRIB_GIS_TESTS_DIR)):
+ (CONTRIB_MODULE_PATH, CONTRIB_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):
if ('.' in f or
# Python 3 byte code dirs (PEP 3147)

6 comments on commit 57f190e

@carljm
Owner

@claudep Can you clarify the reason for this commit (since it's not linked to a ticket or any other rationale)? With the test discovery patch we made an intentional choice to treat the GIS tests less magically and include them along with everything else, using the normal test-skipping decorators in the test files themselves to skip specific tests that cannot be run with a non-spatial backend. This also makes test counts more consistent, since the not-run tests are reported as skipped rather than omitted entirely.

If this choice was causing a specific problem I'm not necessarily opposed to reversing it, but I'd like to know what the problem was.

@carljm
Owner

Oh, never mind - I see the previous commit now. I guess we hadn't removed the magic for the test apps within django.contrib.gis.tests, and you're doing that now. I am still curious though why this follow-up commit was necessary.

@claudep
Collaborator

I broke the test suite with the previous commit. The problem is that loading gis test apps with a non gis-enabled backend chokes when trying to create gis database fields. See http://ci.djangoproject.com/job/Django/2866/database=sqlite3,python=python2.7/console

@carljm
Owner

Yeah, I saw that in the IRC backlog just now. I suppose the other option would be to make the model definitions in models.py conditional on HAS_SPATIAL_DB.

@claudep
Collaborator

Yes, that would also be an option. Just tell me if you'd prefer that option.

@carljm
Owner

Eh, I don't think it's worth changing. It's effectively the same thing; either we add them to INSTALLED_APPS conditionally as you do here, or we always add them to INSTALLED_APPS and make their model definitions conditional. Not seeing a significant advantage to either approach.

Please sign in to comment.
Something went wrong with that request. Please try again.