diff options
| author | Skyiesac <jainsachi1202@gmail.com> | 2025-12-18 16:35:38 +0530 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-12-22 14:02:21 -0500 |
| commit | d0d85cd165e54582cce98cf685252e771460a9d4 (patch) | |
| tree | 60e9ed2fc2ea5926d9f5498bdee07ccc97d4630a /tests/user_commands/tests.py | |
| parent | 6025eab3c509b4de922117e16866bbfe0ee99aa6 (diff) | |
Fixed #36376 -- Fixed --no-color for command help in Python 3.14+.
https://github.com/python/cpython/pull/136809 made `color` default to
True in ArgumentParser.
Diffstat (limited to 'tests/user_commands/tests.py')
| -rw-r--r-- | tests/user_commands/tests.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index afd376307a..0997c10017 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -470,6 +470,34 @@ class CommandTests(SimpleTestCase): ) self.assertFalse(parser.suggest_on_error) + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_color_enabled_by_default(self): + with mock.patch.dict(os.environ, {}, clear=True): + command = BaseCommand() + parser = command.create_parser("prog_name", "subcommand") + self.assertTrue(parser.color) + + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_color_disabled_with_django_colors_nocolor(self): + with mock.patch.dict(os.environ, {"DJANGO_COLORS": "nocolor"}): + command = BaseCommand() + parser = command.create_parser("prog_name", "subcommand") + self.assertFalse(parser.color) + + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_force_color_does_not_affect_argparse_color(self): + with mock.patch.dict(os.environ, {}, clear=True): + command = BaseCommand(force_color=True) + parser = command.create_parser("prog_name", "subcommand") + self.assertTrue(parser.color) + + @unittest.skipUnless(PY314, "Only relevant for Python 3.14+") + def test_no_color_flag_disables_color(self): + with mock.patch.object(sys, "argv", ["manage.py", "mycommand", "--no-color"]): + command = BaseCommand() + parser = command.create_parser("manage.py", "mycommand") + self.assertFalse(parser.color) + class CommandRunTests(AdminScriptTestCase): """ |
