forked from wagtail/wagtail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·106 lines (85 loc) · 3.46 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
import argparse
import os
import shutil
import sys
import warnings
from django.core.management import execute_from_command_line
os.environ["DJANGO_SETTINGS_MODULE"] = "wagtail.test.settings"
def make_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
"--deprecation",
choices=["all", "pending", "imminent", "none"],
default="imminent",
)
parser.add_argument("--postgres", action="store_true")
parser.add_argument("--elasticsearch5", action="store_true")
parser.add_argument("--elasticsearch6", action="store_true")
parser.add_argument("--elasticsearch7", action="store_true")
parser.add_argument("--elasticsearch8", action="store_true")
parser.add_argument("--emailuser", action="store_true")
parser.add_argument("--disabletimezone", action="store_true")
parser.add_argument("--bench", action="store_true")
return parser
def parse_args(args=None):
return make_parser().parse_known_args(args)
def runtests():
args, rest = parse_args()
only_wagtail = r"^wagtail(\.|$)"
if args.deprecation == "all":
# Show all deprecation warnings from all packages
warnings.simplefilter("default", DeprecationWarning)
warnings.simplefilter("default", PendingDeprecationWarning)
elif args.deprecation == "pending":
# Show all deprecation warnings from wagtail
warnings.filterwarnings(
"default", category=DeprecationWarning, module=only_wagtail
)
warnings.filterwarnings(
"default", category=PendingDeprecationWarning, module=only_wagtail
)
elif args.deprecation == "imminent":
# Show only imminent deprecation warnings from wagtail
warnings.filterwarnings(
"default", category=DeprecationWarning, module=only_wagtail
)
elif args.deprecation == "none":
# Deprecation warnings are ignored by default
pass
if args.postgres:
os.environ["DATABASE_ENGINE"] = "django.db.backends.postgresql"
if args.elasticsearch5:
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
os.environ.setdefault("ELASTICSEARCH_VERSION", "5")
elif args.elasticsearch6:
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
os.environ.setdefault("ELASTICSEARCH_VERSION", "6")
elif args.elasticsearch7:
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
os.environ.setdefault("ELASTICSEARCH_VERSION", "7")
elif args.elasticsearch8:
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
os.environ.setdefault("ELASTICSEARCH_VERSION", "8")
elif "ELASTICSEARCH_URL" in os.environ:
# forcibly delete the ELASTICSEARCH_URL setting to skip those tests
del os.environ["ELASTICSEARCH_URL"]
if args.emailuser:
os.environ["USE_EMAIL_USER_MODEL"] = "1"
if args.disabletimezone:
os.environ["DISABLE_TIMEZONE"] = "1"
if args.bench:
benchmarks = [
"wagtail.admin.tests.benches",
]
argv = [sys.argv[0], "test", "-v2"] + benchmarks + rest
else:
argv = [sys.argv[0], "test"] + rest
try:
execute_from_command_line(argv)
finally:
from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
if __name__ == "__main__":
runtests()