3 # This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
7 Creates a simple Django configuration and runs tests for fnpdjango.
9 from __future__ import unicode_literals
13 from os.path import dirname, abspath
14 from optparse import OptionParser
15 from shutil import rmtree
17 from django.conf import settings
18 from fnpdjango.utils.settings import LazyUGettextLazy as _
21 # For convenience configure settings if they are not pre-configured or if we
22 # haven't been provided settings to use by environment variable.
23 if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'):
25 media_root = tempfile.mkdtemp(prefix='djangotest_')
30 'ENGINE': 'django.db.backends.sqlite3',
34 'django.contrib.auth',
35 'django.contrib.contenttypes',
36 'django.contrib.sessions',
37 'django.contrib.sites',
43 MEDIA_ROOT=media_root,
45 'django.middleware.common.CommonMiddleware',
46 'fnpdjango.middleware.URLLocaleMiddleware',
47 'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
49 FNPDJANGO_REALIP = True,
50 ROOT_URLCONF='tests.urls',
53 'BACKEND': 'django.template.backends.django.DjangoTemplates',
56 TEST_LAZY_UGETTEXT_LAZY=_("Lazy setting."),
63 from django.test.runner import DiscoverRunner
66 from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
69 def runtests(*test_args, **kwargs):
70 """Actual test suite entry point."""
73 parent = dirname(abspath(__file__))
74 sys.path.insert(0, parent)
78 from django import setup
84 test_runner = DiscoverRunner(
85 verbosity=kwargs.get('verbosity', 1),
86 interactive=kwargs.get('interactive', False),
87 failfast=kwargs.get('failfast'))
88 failures = test_runner.run_tests(test_args)
93 if __name__ == '__main__':
94 parser = OptionParser()
95 parser.add_option('--failfast', action='store_true',
96 default=False, dest='failfast')
98 (options, args) = parser.parse_args()
100 runtests(failfast=options.failfast, *args)