0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00
wagtail/runtests.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
3.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python
import argparse
2014-02-17 12:03:41 +01:00
import os
import shutil
import sys
import warnings
from django.core.management import execute_from_command_line
2022-03-17 15:37:24 +01:00
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")
2016-11-08 10:21:24 +01:00
parser.add_argument("--elasticsearch5", action="store_true")
2017-12-14 15:20:20 +01:00
parser.add_argument("--elasticsearch6", action="store_true")
parser.add_argument("--elasticsearch7", 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
2022-02-14 14:25:00 +01:00
)
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"
2020-11-04 23:24:59 +01:00
if args.elasticsearch5:
2016-11-08 10:21:24 +01:00
os.environ.setdefault("ELASTICSEARCH_URL", "http://localhost:9200")
os.environ.setdefault("ELASTICSEARCH_VERSION", "5")
2017-12-14 15:20:20 +01:00
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")
2017-11-06 11:51:31 +01:00
elif "ELASTICSEARCH_URL" in os.environ:
# forcibly delete the ELASTICSEARCH_URL setting to skip those tests
del os.environ["ELASTICSEARCH_URL"]
2020-08-14 22:53:14 +02:00
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:
2022-03-17 15:37:24 +01:00
from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
2022-02-14 14:25:00 +01:00
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
2014-02-23 15:57:33 +01:00
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
if __name__ == "__main__":
runtests()