Skip to content

Commit

Permalink
Refs #31546 -- Removed support for boolean values in Command.requires…
Browse files Browse the repository at this point in the history
…_system_checks.

Per deprecation timeline.
  • Loading branch information
felixxm committed Sep 20, 2021
1 parent 2e10abe commit 1cb4950
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 54 deletions.
10 changes: 0 additions & 10 deletions django/core/management/base.py
Expand Up @@ -5,7 +5,6 @@
import argparse
import os
import sys
import warnings
from argparse import ArgumentParser, HelpFormatter
from io import TextIOBase

Expand All @@ -14,7 +13,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import color_style, no_style
from django.db import DEFAULT_DB_ALIAS, connections
from django.utils.deprecation import RemovedInDjango41Warning

ALL_CHECKS = '__all__'

Expand Down Expand Up @@ -252,14 +250,6 @@ def __init__(self, stdout=None, stderr=None, no_color=False, force_color=False):
else:
self.style = color_style(force_color)
self.stderr.style_func = self.style.ERROR
if self.requires_system_checks in [False, True]:
warnings.warn(
"Using a boolean value for requires_system_checks is "
"deprecated. Use '__all__' instead of True, and [] (an empty "
"list) instead of False.",
RemovedInDjango41Warning,
)
self.requires_system_checks = ALL_CHECKS if self.requires_system_checks else []
if (
not isinstance(self.requires_system_checks, (list, tuple)) and
self.requires_system_checks != ALL_CHECKS
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/4.1.txt
Expand Up @@ -249,3 +249,6 @@ to remove usage of these features.
* Support for assigning objects which don't support creating deep copies with
``copy.deepcopy()`` to class attributes in ``TestCase.setUpTestData()`` is
removed.

* Support for using a boolean value in
:attr:`.BaseCommand.requires_system_checks` is removed.
45 changes: 1 addition & 44 deletions tests/user_commands/tests.py
Expand Up @@ -14,9 +14,8 @@
)
from django.db import connection
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, extend_sys_path, ignore_warnings
from django.test.utils import captured_stderr, extend_sys_path
from django.utils import translation
from django.utils.deprecation import RemovedInDjango41Warning

from .management.commands import dance

Expand Down Expand Up @@ -422,45 +421,3 @@ def test_is_ignored_path_false(self):
def test_normalize_path_patterns_truncates_wildcard_base(self):
expected = [os.path.normcase(p) for p in ['foo/bar', 'bar/*/']]
self.assertEqual(normalize_path_patterns(['foo/bar/*', 'bar/*/']), expected)


class DeprecationTests(SimpleTestCase):
def test_requires_system_checks_warning(self):
class Command(BaseCommand):
pass

msg = (
"Using a boolean value for requires_system_checks is deprecated. "
"Use '__all__' instead of True, and [] (an empty list) instead of "
"False."
)
for value in [False, True]:
Command.requires_system_checks = value
with self.assertRaisesMessage(RemovedInDjango41Warning, msg):
Command()

@ignore_warnings(category=RemovedInDjango41Warning)
def test_requires_system_checks_true(self):
class Command(BaseCommand):
requires_system_checks = True

def handle(self, *args, **options):
pass

command = Command()
with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check:
management.call_command(command, skip_checks=False)
mocked_check.assert_called_once_with()

@ignore_warnings(category=RemovedInDjango41Warning)
def test_requires_system_checks_false(self):
class Command(BaseCommand):
requires_system_checks = False

def handle(self, *args, **options):
pass

command = Command()
with mock.patch('django.core.management.base.BaseCommand.check') as mocked_check:
management.call_command(command)
self.assertIs(mocked_check.called, False)

0 comments on commit 1cb4950

Please sign in to comment.