tests are correctly discovered for django < 1.6

This commit is contained in:
Alex Seeholzer 2015-11-13 15:35:36 +01:00
parent 50877c3708
commit cd0daccb56
2 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,9 @@
from os.path import dirname, basename, isfile # import all test_*.py files in directory.
import glob # neccessary for automatic discovery in django <= 1.5
# http://stackoverflow.com/a/15780326/1382740
# import all test_*.py files in directory import unittest
modules = glob.glob(dirname(__file__)+"/test_*.py")
__all__ = [basename(f)[:-3] for f in modules if isfile(f)]
def suite():
return unittest.TestLoader().discover("helpdesk.tests", pattern="test_*.py")

View File

@ -97,13 +97,13 @@ class QuickDjangoTest(object):
# see: http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app # see: http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app
try: try:
# Django <= 1.8 # Django >= 1.6
from django.test.simple import DjangoTestSuiteRunner
test_runner = DjangoTestSuiteRunner(verbosity=1)
except ImportError:
# Django >= 1.8
from django.test.runner import DiscoverRunner from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner(verbosity=1) test_runner = DiscoverRunner(verbosity=1)
except ImportError:
# Django <= 1.5
from django.test.simple import DjangoTestSuiteRunner
test_runner = DjangoTestSuiteRunner(verbosity=1)
if django.VERSION >= (1, 7): if django.VERSION >= (1, 7):
django.setup() django.setup()