2016-06-17 14:06:21 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
import django
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
2022-02-14 13:25:00 +00:00
|
|
|
parser.addoption(
|
|
|
|
"--deprecation",
|
|
|
|
choices=["all", "pending", "imminent", "none"],
|
|
|
|
default="pending",
|
|
|
|
)
|
|
|
|
parser.addoption("--postgres", action="store_true")
|
|
|
|
parser.addoption("--elasticsearch", action="store_true")
|
2016-06-17 14:06:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def pytest_configure(config):
|
2022-02-14 13:25:00 +00:00
|
|
|
deprecation = config.getoption("deprecation")
|
2016-06-17 14:06:21 +00:00
|
|
|
|
2022-02-14 13:25:00 +00:00
|
|
|
only_wagtail = r"^wagtail(\.|$)"
|
|
|
|
if deprecation == "all":
|
2016-06-17 14:06:21 +00:00
|
|
|
# Show all deprecation warnings from all packages
|
2022-02-14 13:25:00 +00:00
|
|
|
warnings.simplefilter("default", DeprecationWarning)
|
|
|
|
warnings.simplefilter("default", PendingDeprecationWarning)
|
|
|
|
elif deprecation == "pending":
|
2016-06-17 14:06:21 +00:00
|
|
|
# Show all deprecation warnings from wagtail
|
2022-02-14 13:25:00 +00:00
|
|
|
warnings.filterwarnings(
|
|
|
|
"default", category=DeprecationWarning, module=only_wagtail
|
|
|
|
)
|
|
|
|
warnings.filterwarnings(
|
|
|
|
"default", category=PendingDeprecationWarning, module=only_wagtail
|
|
|
|
)
|
|
|
|
elif deprecation == "imminent":
|
2016-06-17 14:06:21 +00:00
|
|
|
# Show only imminent deprecation warnings from wagtail
|
2022-02-14 13:25:00 +00:00
|
|
|
warnings.filterwarnings(
|
|
|
|
"default", category=DeprecationWarning, module=only_wagtail
|
|
|
|
)
|
|
|
|
elif deprecation == "none":
|
2016-06-17 14:06:21 +00:00
|
|
|
# Deprecation warnings are ignored by default
|
|
|
|
pass
|
|
|
|
|
2022-02-14 13:25:00 +00:00
|
|
|
if config.getoption("postgres"):
|
|
|
|
os.environ["DATABASE_ENGINE"] = "django.db.backends.postgresql"
|
2016-06-17 14:06:21 +00:00
|
|
|
|
|
|
|
# Setup django after processing the pytest arguments so that the env
|
|
|
|
# variables are available in the settings
|
2022-03-17 14:37:24 +00:00
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wagtail.test.settings")
|
2016-06-17 14:06:21 +00:00
|
|
|
django.setup()
|
|
|
|
|
2018-10-29 10:25:49 +00:00
|
|
|
# Activate a language: This affects HTTP header HTTP_ACCEPT_LANGUAGE sent by
|
|
|
|
# the Django test client.
|
|
|
|
from django.utils import translation
|
2022-02-14 13:25:00 +00:00
|
|
|
|
2018-10-29 10:25:49 +00:00
|
|
|
translation.activate("en")
|
|
|
|
|
2022-03-17 14:37:24 +00:00
|
|
|
from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
|
2022-02-14 13:25:00 +00:00
|
|
|
|
2016-06-17 14:06:21 +00:00
|
|
|
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
|
|
|
|
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_unconfigure(config):
|
2022-03-17 14:37:24 +00:00
|
|
|
from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
|
2022-02-14 13:25:00 +00:00
|
|
|
|
2016-06-17 14:06:21 +00:00
|
|
|
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
|
|
|
|
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
|