Fixed #21849 -- Included the count of silenced system checks in output.
This commit is contained in:
parent
3e4dc5ecf2
commit
2b6914049a
|
@ -365,11 +365,12 @@ class BaseCommand(object):
|
|||
Raises CommandError for any serious message (error or critical errors).
|
||||
If there are only light messages (like warnings), they are printed to
|
||||
stderr and no exception is raised.
|
||||
|
||||
"""
|
||||
all_issues = checks.run_checks(app_configs=app_configs, tags=tags)
|
||||
|
||||
msg = ""
|
||||
visible_issue_count = 0 # excludes silenced warnings
|
||||
|
||||
if all_issues:
|
||||
debugs = [e for e in all_issues if e.level < checks.INFO and not e.is_silenced()]
|
||||
infos = [e for e in all_issues if checks.INFO <= e.level < checks.WARNING and not e.is_silenced()]
|
||||
|
@ -386,6 +387,7 @@ class BaseCommand(object):
|
|||
|
||||
for issues, group_name in sorted_issues:
|
||||
if issues:
|
||||
visible_issue_count += len(issues)
|
||||
formatted = (
|
||||
color_style().ERROR(force_str(e))
|
||||
if e.is_serious()
|
||||
|
@ -393,21 +395,22 @@ class BaseCommand(object):
|
|||
for e in issues)
|
||||
formatted = "\n".join(sorted(formatted))
|
||||
msg += '\n%s:\n%s\n' % (group_name, formatted)
|
||||
|
||||
if msg:
|
||||
msg = "System check identified some issues:\n%s" % msg
|
||||
|
||||
if display_num_errors:
|
||||
if msg:
|
||||
msg += '\n'
|
||||
msg += "System check identified %s." % (
|
||||
"no issues" if len(all_issues) == 0 else
|
||||
"1 issue" if len(all_issues) == 1 else
|
||||
"%s issues" % len(all_issues)
|
||||
msg += "System check identified %s (%s silenced)." % (
|
||||
"no issues" if visible_issue_count == 0 else
|
||||
"1 issue" if visible_issue_count == 1 else
|
||||
"%s issues" % visible_issue_count,
|
||||
len(all_issues) - visible_issue_count,
|
||||
)
|
||||
|
||||
if any(e.is_serious() and not e.is_silenced() for e in all_issues):
|
||||
raise CommandError(msg)
|
||||
elif msg and all_issues:
|
||||
elif msg and visible_issue_count:
|
||||
self.stderr.write(msg)
|
||||
elif msg:
|
||||
self.stdout.write(msg)
|
||||
|
|
|
@ -1124,7 +1124,7 @@ class ManageCheck(AdminScriptTestCase):
|
|||
args = ['check']
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(err)
|
||||
self.assertEqual(out, 'System check identified no issues.\n')
|
||||
self.assertEqual(out, 'System check identified no issues (0 silenced).\n')
|
||||
|
||||
def test_app_with_import(self):
|
||||
""" manage.py check does not raise errors when an app imports a base
|
||||
|
@ -1139,7 +1139,7 @@ class ManageCheck(AdminScriptTestCase):
|
|||
args = ['check']
|
||||
out, err = self.run_manage(args)
|
||||
self.assertNoOutput(err)
|
||||
self.assertEqual(out, 'System check identified no issues.\n')
|
||||
self.assertEqual(out, 'System check identified no issues (0 silenced).\n')
|
||||
|
||||
def test_output_format(self):
|
||||
""" All errors/warnings should be sorted by level and by message. """
|
||||
|
@ -1163,7 +1163,7 @@ class ManageCheck(AdminScriptTestCase):
|
|||
"obj: First warning\n"
|
||||
"\tHINT: Hint\n"
|
||||
"\n"
|
||||
"System check identified 3 issues.\n"
|
||||
"System check identified 3 issues (0 silenced).\n"
|
||||
)
|
||||
self.assertEqual(err, expected_err)
|
||||
self.assertNoOutput(out)
|
||||
|
@ -1191,7 +1191,7 @@ class ManageCheck(AdminScriptTestCase):
|
|||
"WARNINGS:\n"
|
||||
"?: A warning\n"
|
||||
"\n"
|
||||
"System check identified 1 issue.\n"
|
||||
"System check identified 1 issue (0 silenced).\n"
|
||||
)
|
||||
self.assertEqual(err, expected_err)
|
||||
self.assertNoOutput(out)
|
||||
|
|
|
@ -7,7 +7,7 @@ import sys
|
|||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.core import checks
|
||||
from django.core.checks import Error
|
||||
from django.core.checks import Error, Warning
|
||||
from django.core.checks.registry import CheckRegistry
|
||||
from django.core.checks.compatibility.django_1_6_0 import check_1_6_compatibility
|
||||
from django.core.management.base import CommandError
|
||||
|
@ -195,12 +195,22 @@ class CheckCommandTests(TestCase):
|
|||
self.assertRaises(CommandError, call_command, 'check', tags=['missingtag'])
|
||||
|
||||
|
||||
def custom_system_check(app_configs, **kwargs):
|
||||
def custom_error_system_check(app_configs, **kwargs):
|
||||
return [
|
||||
Error(
|
||||
'Error',
|
||||
hint=None,
|
||||
id='mycheck.E001',
|
||||
id='myerrorcheck.E001',
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def custom_warning_system_check(app_configs, **kwargs):
|
||||
return [
|
||||
Warning(
|
||||
'Warning',
|
||||
hint=None,
|
||||
id='mywarningcheck.E001',
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -209,15 +219,39 @@ class SilencingCheckTests(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.old_stdout, self.old_stderr = sys.stdout, sys.stderr
|
||||
sys.stdout, sys.stderr = StringIO(), StringIO()
|
||||
self.stdout, self.stderr = StringIO(), StringIO()
|
||||
sys.stdout, sys.stderr = self.stdout, self.stderr
|
||||
|
||||
def tearDown(self):
|
||||
sys.stdout, sys.stderr = self.old_stdout, self.old_stderr
|
||||
|
||||
@override_settings(SILENCED_SYSTEM_CHECKS=['mycheck.E001'])
|
||||
@override_system_checks([custom_system_check])
|
||||
def test_simple(self):
|
||||
@override_settings(SILENCED_SYSTEM_CHECKS=['myerrorcheck.E001'])
|
||||
@override_system_checks([custom_error_system_check])
|
||||
def test_silenced_error(self):
|
||||
out = StringIO()
|
||||
err = StringIO()
|
||||
try:
|
||||
call_command('check')
|
||||
call_command('check', stdout=out, stderr=err)
|
||||
except CommandError:
|
||||
self.fail("The mycheck.E001 check should be silenced.")
|
||||
self.assertEqual(out.getvalue(), '')
|
||||
self.assertEqual(
|
||||
err.getvalue(),
|
||||
'System check identified some issues:\n\n'
|
||||
'ERRORS:\n'
|
||||
'?: (myerrorcheck.E001) Error\n\n'
|
||||
'System check identified 1 issue (0 silenced).\n'
|
||||
)
|
||||
|
||||
@override_settings(SILENCED_SYSTEM_CHECKS=['mywarningcheck.E001'])
|
||||
@override_system_checks([custom_warning_system_check])
|
||||
def test_silenced_warning(self):
|
||||
out = StringIO()
|
||||
err = StringIO()
|
||||
try:
|
||||
call_command('check', stdout=out, stderr=err)
|
||||
except CommandError:
|
||||
self.fail("The mycheck.E001 check should be silenced.")
|
||||
|
||||
self.assertEqual(out.getvalue(), 'System check identified no issues (1 silenced).\n')
|
||||
self.assertEqual(err.getvalue(), '')
|
||||
|
|
|
@ -333,7 +333,7 @@ class SettingsConfigTest(AdminScriptTestCase):
|
|||
# validate is just an example command to trigger settings configuration
|
||||
out, err = self.run_manage(['validate'])
|
||||
self.assertNoOutput(err)
|
||||
self.assertOutput(out, "System check identified no issues.")
|
||||
self.assertOutput(out, "System check identified no issues (0 silenced).")
|
||||
|
||||
|
||||
def dictConfig(config):
|
||||
|
|
Loading…
Reference in New Issue