0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 13:10:14 +01:00
wagtail/runtests.py
Tim Heap 0097f770fd Add options to filter deprecation warnings in tests
The test output was extremely noisy with deprecation warnings. Half of
these warnings were caused by external modules like django-taggit, and
could be ignored. The warnings caused by Wagtail got lost in the noise
though, rendering the test output useless for finding warnings. By
default, the tests now only print deprecation warnings if raised by
Wagtail.

Use `./runtests.py --deprecation=all` if you want all the warnings to be
printed. This is useful when we want to fix third party packages before
they break from being too outdated.

Use `./runtests.py --deprecation=pending` if you want the default
behaviour.

Use `./runtests.py --deprecation=imminent` if you only want imminent
DeprecationWarnings, ignoring PendingDeprecationWarnings.

Use `./runtests.py --deprecation=none` if you want to ignore all
deprecation warnings.
2016-04-12 17:00:33 +01:00

64 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python
import sys
import os
import shutil
import warnings
import argparse
from django.core.management import execute_from_command_line
os.environ['DJANGO_SETTINGS_MODULE'] = 'wagtail.tests.settings'
def make_parser():
parser = argparse.ArgumentParser()
parser.add_argument('--deprecation', choices=['all', 'pending', 'imminent', 'none'], default='pending')
parser.add_argument('--postgres', action='store_true')
parser.add_argument('--elasticsearch', action='store_true')
parser.add_argument('rest', nargs='*')
return parser
def parse_args(args=None):
return make_parser().parse_args(args)
def runtests():
args = 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_psycopg2'
if args.elasticsearch:
os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
argv = [sys.argv[0], 'test'] + args.rest
try:
execute_from_command_line(argv)
finally:
from wagtail.tests.settings import STATIC_ROOT, MEDIA_ROOT
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
if __name__ == '__main__':
runtests()