diff --git a/runtests.py b/runtests.py index 2e9a9de23..c9bcbbba2 100755 --- a/runtests.py +++ b/runtests.py @@ -4,6 +4,7 @@ import sys import os import shutil import warnings +import argparse from django.core.management import execute_from_command_line @@ -11,22 +12,45 @@ 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(): - # Don't ignore DeprecationWarnings - warnings.simplefilter('default', DeprecationWarning) - warnings.simplefilter('default', PendingDeprecationWarning) + args = parse_args() - args = sys.argv[1:] + 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 '--postgres' in args: + if args.postgres: os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql_psycopg2' - args.remove('--postgres') - if '--elasticsearch' in args: + if args.elasticsearch: os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200') - args.remove('--elasticsearch') - argv = sys.argv[:1] + ['test'] + args + argv = [sys.argv[0], 'test'] + args.rest try: execute_from_command_line(argv) finally: