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,
44 TEST_LAZY_UGETTEXT_LAZY=_("Lazy setting."),
50 from django.test.runner import DiscoverRunner
53 from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
56 def runtests(*test_args, **kwargs):
57 """Actual test suite entry point."""
60 parent = dirname(abspath(__file__))
61 sys.path.insert(0, parent)
65 from django import setup
71 test_runner = DiscoverRunner(
72 verbosity=kwargs.get('verbosity', 1),
73 interactive=kwargs.get('interactive', False),
74 failfast=kwargs.get('failfast'))
75 failures = test_runner.run_tests(test_args)
80 if __name__ == '__main__':
81 parser = OptionParser()
82 parser.add_option('--failfast', action='store_true',
83 default=False, dest='failfast')
85 (options, args) = parser.parse_args()
87 runtests(failfast=options.failfast, *args)