From 5688677a89f6d8f0168290ca069e473c15b7617c Mon Sep 17 00:00:00 2001 From: Michael Hrivnak Date: Sat, 8 Mar 2014 01:44:53 -0500 Subject: moved django test app settings to the django test app module ... to guarantee the settings get executed before any code in that app. Since python's unittest.TestLoader does not guarantee in what order it will import modules while hunting for test cases, the unit tests could fail to even load if tests.django_test_app.models was loaded before tests.test_django. This failure was seen on ARM machines, which happened to traverse the module tree in an inconvenient order. --- CREDITS | 1 + tests/django_test_app/__init__.py | 24 ++++++++++++++++++++++++ tests/test_django.py | 12 ------------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CREDITS b/CREDITS index 0eb13f0..75f8e2e 100644 --- a/CREDITS +++ b/CREDITS @@ -18,6 +18,7 @@ Contributors The project has received contributions from (in alphabetical order): * Raphaƫl Barrois (https://github.com/rbarrois) +* Michael Hrivnak (https://github.com/mhrivnak) Contributor license agreement diff --git a/tests/django_test_app/__init__.py b/tests/django_test_app/__init__.py index e69de29..1c692b0 100644 --- a/tests/django_test_app/__init__.py +++ b/tests/django_test_app/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2012-2014 The python-semanticversion project +# This code is distributed under the two-clause BSD License. + +try: # pragma: no cover + from django.conf import settings + django_loaded = True +except ImportError: # pragma: no cover + django_loaded = False + + +if django_loaded: # pragma: no cover + if not settings.configured: + settings.configure( + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'tests/db/test.sqlite', + } + }, + INSTALLED_APPS=[ + 'tests.django_test_app', + ] + ) diff --git a/tests/test_django.py b/tests/test_django.py index 0cb480b..35193fa 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -18,18 +18,6 @@ except ImportError: # pragma: no cover django_loaded = False if django_loaded: # pragma: no cover - if not settings.configured: - settings.configure( - DATABASES={ - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'tests/db/test.sqlite', - } - }, - INSTALLED_APPS=[ - 'tests.django_test_app', - ] - ) from .django_test_app import models from django.core import serializers -- cgit v1.2.1