0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-22 11:07:57 +01:00
wagtail/conftest.py
Bertrand Bordage 9db5b45ec7 Replace every remaining mention of postgresql_psycopg2.
PostgreSQL search backend were not running because of this since 67b1ddb665 (diff-c2cc727a5e1fca9050dea34af68aa13c)
2017-10-18 21:10:49 +01:00

52 lines
1.9 KiB
Python

from __future__ import absolute_import, unicode_literals
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':
# Show all deprecation warnings from all packages
warnings.simplefilter('default', DeprecationWarning)
warnings.simplefilter('default', PendingDeprecationWarning)
elif 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 deprecation == 'imminent':
# Show only imminent deprecation warnings from wagtail
warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtail)
elif deprecation == 'none':
# Deprecation warnings are ignored by default
pass
if config.getoption('postgres'):
os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql'
# Setup django after processing the pytest arguments so that the env
# variables are available in the settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wagtail.tests.settings')
django.setup()
from wagtail.tests.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.tests.settings import MEDIA_ROOT, STATIC_ROOT
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)