mirror of
https://github.com/django/django.git
synced 2025-11-17 18:48:15 +00:00
Fixed #36321 -- Updated test for suggest_on_error on Python 3.14.
Updated test_invalid_choice_db_option to handle the new error message format with suggestions on Python 3.14.
This commit is contained in:
parent
987d418ae2
commit
f4a7255378
3 changed files with 19 additions and 10 deletions
|
|
@ -15,7 +15,7 @@ from django.core import checks
|
|||
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.version import PY314, PY315
|
||||
from django.utils.version import PY314
|
||||
|
||||
ALL_CHECKS = "__all__"
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ class CommandParser(ArgumentParser):
|
|||
):
|
||||
self.missing_args_message = missing_args_message
|
||||
self.called_from_command_line = called_from_command_line
|
||||
if PY314 and not PY315:
|
||||
if PY314:
|
||||
kwargs.setdefault("suggest_on_error", True)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ from django.test import LiveServerTestCase, SimpleTestCase, TestCase, override_s
|
|||
from django.test.utils import captured_stderr, captured_stdout
|
||||
from django.urls import path
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.version import PY313, get_docs_version
|
||||
from django.utils.version import PY313, PY314, get_docs_version
|
||||
from django.views.static import serve
|
||||
|
||||
from . import urls
|
||||
|
|
@ -2464,10 +2464,17 @@ class Discovery(SimpleTestCase):
|
|||
|
||||
class CommandDBOptionChoiceTests(SimpleTestCase):
|
||||
def test_invalid_choice_db_option(self):
|
||||
expected_error = (
|
||||
r"Error: argument --database: invalid choice: 'deflaut' "
|
||||
r"\(choose from '?default'?, '?other'?\)"
|
||||
)
|
||||
# Update expected error based on Python version
|
||||
if PY314:
|
||||
expected_error = (
|
||||
r"Error: argument --database: invalid choice: 'deflaut', "
|
||||
r"maybe you meant 'default'\? \(choose from default, other\)"
|
||||
)
|
||||
else:
|
||||
expected_error = (
|
||||
r"Error: argument --database: invalid choice: 'deflaut' "
|
||||
r"\(choose from '?default'?, '?other'?\)"
|
||||
)
|
||||
args = [
|
||||
"changepassword",
|
||||
"createsuperuser",
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from django.db import connection
|
|||
from django.test import SimpleTestCase, override_settings
|
||||
from django.test.utils import captured_stderr, extend_sys_path
|
||||
from django.utils import translation
|
||||
from django.utils.version import PY314, PY315
|
||||
from django.utils.version import PY314
|
||||
|
||||
from .management.commands import dance
|
||||
from .utils import AssertFormatterFailureCaughtContext
|
||||
|
|
@ -456,21 +456,23 @@ class CommandTests(SimpleTestCase):
|
|||
self.assertIn("Working...", out.getvalue())
|
||||
self.assertIs(mocked_flush.called, True)
|
||||
|
||||
@unittest.skipUnless(PY314 and not PY315, "Requires Python 3.14")
|
||||
@unittest.skipUnless(PY314, "Requires Python 3.14")
|
||||
def test_suggest_on_error_defaults_true(self):
|
||||
"""
|
||||
CommandParser sets suggest_on_error=True on Python 3.14.
|
||||
"""
|
||||
command = BaseCommand()
|
||||
command._called_from_command_line = True
|
||||
parser = command.create_parser("prog_name", "subcommand")
|
||||
self.assertTrue(parser.suggest_on_error)
|
||||
|
||||
@unittest.skipUnless(PY314 and not PY315, "Requires Python 3.14")
|
||||
@unittest.skipUnless(PY314, "Requires Python 3.14")
|
||||
def test_suggest_on_error_custom(self):
|
||||
"""
|
||||
Explicit suggest_on_error=False is respected.
|
||||
"""
|
||||
command = BaseCommand()
|
||||
command._called_from_command_line = True
|
||||
parser = command.create_parser(
|
||||
"prog_name", "subcommand", suggest_on_error=False
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue