forked from jazzband/django-simple-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
executable file
·91 lines (77 loc) · 2.45 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
91
#!/usr/bin/env python
import logging
from os.path import abspath, dirname, join
from shutil import rmtree
import sys
import django
from django.conf import settings
from django.test.runner import DiscoverRunner
sys.path.insert(0, abspath(dirname(__file__)))
media_root = join(abspath(dirname(__file__)), "test_files")
rmtree(media_root, ignore_errors=True)
installed_apps = [
"simple_history.tests",
"simple_history.tests.custom_user",
"simple_history.tests.external",
"simple_history.registry_tests.migration_test_app",
"simple_history",
"django.contrib.contenttypes",
"django.contrib.auth",
"django.contrib.sessions",
"django.contrib.admin",
"django.contrib.messages",
]
class DisableMigrations:
def __contains__(self, item):
return True
def __getitem__(self, item):
return None
DEFAULT_SETTINGS = dict(
ALLOWED_HOSTS=["localhost"],
AUTH_USER_MODEL="custom_user.CustomUser",
ROOT_URLCONF="simple_history.tests.urls",
MEDIA_ROOT=media_root,
STATIC_URL="/static/",
INSTALLED_APPS=installed_apps,
DATABASES={
"default": {"ENGINE": "django.db.backends.sqlite3"},
"other": {"ENGINE": "django.db.backends.sqlite3"},
},
MIGRATION_MODULES=DisableMigrations(),
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]
},
}
],
)
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
]
if django.__version__ >= "2.0":
DEFAULT_SETTINGS["MIDDLEWARE"] = MIDDLEWARE
else:
DEFAULT_SETTINGS["MIDDLEWARE_CLASSES"] = MIDDLEWARE
def main():
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
tags = [t.split("=")[1] for t in sys.argv if t.startswith("--tag")]
failures = DiscoverRunner(failfast=False, tags=tags).run_tests(
["simple_history.tests"]
)
failures |= DiscoverRunner(failfast=False, tags=tags).run_tests(
["simple_history.registry_tests"]
)
sys.exit(failures)
if __name__ == "__main__":
logging.basicConfig()
main()