forked from berinhard/model_mommy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·70 lines (54 loc) · 1.98 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
from os.path import dirname, join
import sys
from optparse import OptionParser
import warnings
def parse_args():
parser = OptionParser()
parser.add_option('--use-tz', dest='USE_TZ', action='store_true')
return parser.parse_args()
def configure_settings(options):
from django.conf import settings
# If DJANGO_SETTINGS_MODULE envvar exists the settings will be
# configured by it. Otherwise it will use the parameters bellow.
if not settings.configured:
params = dict(
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
INSTALLED_APPS = (
'django.contrib.contenttypes',
'test.generic',
'test.ambiguous',
),
SITE_ID=1,
TEST_ROOT=join(dirname(__file__), 'test', 'generic', 'tests'),
)
# Force the use of timezone aware datetime and change Django's warning to
# be treated as errors.
if getattr(options, 'USE_TZ', False):
params.update(USE_TZ=True)
warnings.filterwarnings('error', r"DateTimeField received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')
# Configure Django's settings
settings.configure(**params)
return settings
def get_runner(settings):
'''
Asks Django for the TestRunner defined in settings or the default one.
'''
from django.test.utils import get_runner
TestRunner = get_runner(settings)
return TestRunner(verbosity=1, interactive=True, failfast=False)
def runtests(options=None, labels=None):
if not labels:
labels = ['generic']
settings = configure_settings(options)
runner = get_runner(settings)
sys.exit(runner.run_tests(labels))
if __name__ == '__main__':
options, labels = parse_args()
runtests(options, labels)