-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruntests.py
90 lines (81 loc) · 2.59 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os.path
import subprocess
import sys
import django
from django.conf import settings
DATABASES = {
'postgresql': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_database_constraints',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
},
'mysql': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_dummy',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
},
# can't figure out how to run sqlite3 with multithreaded support
# during tests, so worthless trying this
#'sqlite3': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'TEST_NAME': os.path.join(os.path.realpath(os.path.dirname(__file__)), 'test_sqlite_database'),
#},
}
settings.configure(
DEBUG=True,
INSTALLED_APPS = [
'django_database_constraints',
],
DATABASES = {
'default': DATABASES['postgresql'],
},
CONTEXT_PROCESSORS=[],
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [],
}
},
]
)
django.setup()
# after we have some settings
from django.test.utils import override_settings
def run_against(db):
@override_settings(DATABASES = { 'default': DATABASES[db] })
def run_tests():
print("Running tests against %s database." % db)
#from django.test.simple import DjangoTestSuiteRunner
#test_runner = DjangoTestSuiteRunner(verbosity=1, failfast=False)
from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner(verbosity=1, failfast=False)
failures = test_runner.run_tests(['django_database_constraints', ])
if failures: #pragma no cover
sys.exit(failures)
run_tests()
if len(sys.argv) == 1: #pragma no cover
# we can't call run_against() multiple times and have it actually work
# (possibly only since Django 1.6) for reasons I don't have time to
# track down now (it's ignoring @override_settings on subsequent calls)
failures = 0
for db in DATABASES.keys():
args = [ sys.executable, sys.argv[0], db ]
rc = subprocess.call(args)
failures += rc
if failures != 0:
print("\nTOTAL FAILURES: %i" % failures)
sys.exit(failures)
elif len(sys.argv) == 2:
run_against(sys.argv[1])
else: #pragma: no cover
sys.stderr.write("Cannot run against multiple databases in one run.\n")
sys.exit(100)