diff --git a/django/core/checks/messages.py b/django/core/checks/messages.py index e770f9ccce..23e9d5a794 100644 --- a/django/core/checks/messages.py +++ b/django/core/checks/messages.py @@ -48,8 +48,8 @@ class CheckMessage(object): return "<%s: level=%r, msg=%r, hint=%r, obj=%r, id=%r>" % \ (self.__class__.__name__, self.level, self.msg, self.hint, self.obj, self.id) - def is_serious(self): - return self.level >= ERROR + def is_serious(self, level=ERROR): + return self.level >= level def is_silenced(self): from django.conf import settings diff --git a/django/core/management/base.py b/django/core/management/base.py index 6bdfe31ac5..f77add2085 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -355,7 +355,7 @@ class BaseCommand(object): translation.activate(saved_locale) def check(self, app_configs=None, tags=None, display_num_errors=False, - include_deployment_checks=False): + include_deployment_checks=False, fail_level=checks.ERROR): """ Uses the system check framework to validate entire Django project. Raises CommandError for any serious message (error or critical errors). @@ -409,7 +409,7 @@ class BaseCommand(object): len(all_issues) - visible_issue_count, ) - if any(e.is_serious() and not e.is_silenced() for e in all_issues): + if any(e.is_serious(fail_level) and not e.is_silenced() for e in all_issues): msg = self.style.ERROR("SystemCheckError: %s" % header) + body + footer raise SystemCheckError(msg) else: diff --git a/django/core/management/commands/check.py b/django/core/management/commands/check.py index f50d234f8c..5a66f7ac59 100644 --- a/django/core/management/commands/check.py +++ b/django/core/management/commands/check.py @@ -20,6 +20,16 @@ class Command(BaseCommand): help='List available tags.') parser.add_argument('--deploy', action='store_true', dest='deploy', help='Check deployment settings.') + parser.add_argument( + '--fail-level', + default='ERROR', + choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'], + dest='fail_level', + help=( + 'Message level that will cause the command to exit with a ' + 'non-zero status. Default is ERROR.' + ), + ) def handle(self, *app_labels, **options): include_deployment_checks = options['deploy'] @@ -49,4 +59,5 @@ class Command(BaseCommand): tags=tags, display_num_errors=True, include_deployment_checks=include_deployment_checks, + fail_level=getattr(checks, options['fail_level']), ) diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index a48a7043fd..ee9fd0cc83 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -147,6 +147,16 @@ Or you could run it directly on a production or staging deployment to verify that the correct settings are in use (omitting ``--settings``). You could even make it part of your integration test suite. +.. django-admin-option:: --fail-level + +.. versionadded:: 1.10 + +Specifies the message level that will cause the command to exit with a non-zero +status. Default is ``ERROR``. + +Available levels are: ``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO``, and +``DEBUG``. + compilemessages --------------- diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 1eada416f6..2c41db2b72 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -150,7 +150,9 @@ Internationalization Management Commands ^^^^^^^^^^^^^^^^^^^ -* ... +* The new :djadminopt:`--fail-level` option of the :djadmin:`check` command + allows specifying the message level that will cause the command to exit with + a non-zero status. Migrations ^^^^^^^^^^ diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py index 03bc01f843..7ae7b633e0 100644 --- a/tests/check_framework/tests.py +++ b/tests/check_framework/tests.py @@ -116,7 +116,7 @@ def simple_system_check(**kwargs): def tagged_system_check(**kwargs): tagged_system_check.kwargs = kwargs - return [] + return [checks.Warning('System Check')] tagged_system_check.tags = ['simpletag'] @@ -192,6 +192,11 @@ class CheckCommandTests(SimpleTestCase): call_command('check', deploy=True, tags=['deploymenttag']) self.assertIn('Deployment Check', sys.stderr.getvalue()) + @override_system_checks([tagged_system_check]) + def test_fail_level(self): + with self.assertRaises(CommandError): + call_command('check', fail_level='WARNING') + def custom_error_system_check(app_configs, **kwargs): return [