12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import os
- import shutil
- import warnings
- import django
- def pytest_addoption(parser):
- parser.addoption(
- "--deprecation",
- choices=["all", "pending", "imminent", "none"],
- default="pending",
- )
- parser.addoption("--postgres", action="store_true")
- parser.addoption("--elasticsearch", action="store_true")
- def pytest_configure(config):
- deprecation = config.getoption("deprecation")
- only_wagtail = r"^wagtail(\.|$)"
- if deprecation == "all":
-
- warnings.simplefilter("default", DeprecationWarning)
- warnings.simplefilter("default", PendingDeprecationWarning)
- elif deprecation == "pending":
-
- warnings.filterwarnings(
- "default", category=DeprecationWarning, module=only_wagtail
- )
- warnings.filterwarnings(
- "default", category=PendingDeprecationWarning, module=only_wagtail
- )
- elif deprecation == "imminent":
-
- warnings.filterwarnings(
- "default", category=DeprecationWarning, module=only_wagtail
- )
- elif deprecation == "none":
-
- pass
- if config.getoption("postgres"):
- os.environ["DATABASE_ENGINE"] = "django.db.backends.postgresql"
-
-
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wagtail.test.settings")
- django.setup()
-
-
- from django.utils import translation
- translation.activate("en")
- from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
- shutil.rmtree(STATIC_ROOT, ignore_errors=True)
- shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
- def pytest_unconfigure(config):
- from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
- shutil.rmtree(STATIC_ROOT, ignore_errors=True)
- shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
|