-
Notifications
You must be signed in to change notification settings - Fork 86
/
runtests.py
74 lines (60 loc) · 1.88 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
#!/usr/bin/env python
import sys
import django
from django.conf import settings
from django.test.utils import get_runner
from collections import defaultdict
def configure(databases):
from faker import Faker
fake = Faker()
settings.configure(
DATABASES=databases,
INSTALLED_APPS=(
'django_seed',
'django_nose',
),
TEST_RUNNER='django_nose.NoseTestSuiteRunner',
NOSE_ARGS=[
'--exe', # nose will skip files with the executable bit set without this
'--with-coverage',
'--cover-package=django_seed',
],
SITE_ID=1,
SECRET_KEY=fake.sha1(),
)
if not settings.configured:
argv = sys.argv[1:]
args=defaultdict(list)
for k, v in ((k.lstrip('-'), v) for k,v in (a.split('=') for a in sys.argv[1:])):
args[k].append(v)
# Remove all args that are already
sys.argv = list(filter(lambda arg: any(arg_name.startswith(arg) for arg_name in [
'--database'
]), sys.argv))
databases = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
# Used for tests in Github Actions
# Refer to .github/workflows/test.yml to see the Postgres service that is
# being hosted
if 'postgres' in args['database']:
databases['default'] = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbtest',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'localhost',
'PORT': '5432',
}
configure(databases)
def runtests():
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=1, interactive=True, failfast=False)
failures = test_runner.run_tests(['django_seed', ])
sys.exit(failures)
if __name__ == '__main__':
runtests()