mirror of
https://github.com/django/django.git
synced 2024-11-21 19:09:18 +01:00
Refs #35844 -- Expanded compatibility for expected error messages in command tests on Python 3.12 and 3.13.
Updated CommandTests.test_subparser_invalid_option and CommandDBOptionChoiceTests.test_invalid_choice_db_option to use assertRaisesRegex() for compatibility with modified error messages in Python 3.12, 3.13, and 3.14+..
This commit is contained in:
parent
d7f78eb5d6
commit
fc22fdd34f
@ -34,7 +34,7 @@ from django.db.migrations.recorder import MigrationRecorder
|
||||
from django.test import LiveServerTestCase, SimpleTestCase, TestCase, override_settings
|
||||
from django.test.utils import captured_stderr, captured_stdout
|
||||
from django.urls import path
|
||||
from django.utils.version import PY313, PY314, get_docs_version
|
||||
from django.utils.version import PY313, get_docs_version
|
||||
from django.views.static import serve
|
||||
|
||||
from . import urls
|
||||
@ -2355,16 +2355,10 @@ class Discovery(SimpleTestCase):
|
||||
|
||||
class CommandDBOptionChoiceTests(SimpleTestCase):
|
||||
def test_invalid_choice_db_option(self):
|
||||
if PY314:
|
||||
expected_error = (
|
||||
"Error: argument --database: invalid choice: 'deflaut' "
|
||||
"(choose from default, other)"
|
||||
)
|
||||
else:
|
||||
expected_error = (
|
||||
"Error: argument --database: invalid choice: 'deflaut' "
|
||||
"(choose from 'default', 'other')"
|
||||
)
|
||||
expected_error = (
|
||||
r"Error: argument --database: invalid choice: 'deflaut' "
|
||||
r"\(choose from '?default'?, '?other'?\)"
|
||||
)
|
||||
args = [
|
||||
"changepassword",
|
||||
"createsuperuser",
|
||||
@ -2384,7 +2378,7 @@ class CommandDBOptionChoiceTests(SimpleTestCase):
|
||||
]
|
||||
|
||||
for arg in args:
|
||||
with self.assertRaisesMessage(CommandError, expected_error):
|
||||
with self.assertRaisesRegex(CommandError, expected_error):
|
||||
call_command(arg, "--database", "deflaut", verbosity=0)
|
||||
|
||||
|
||||
|
@ -20,7 +20,6 @@ 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
|
||||
|
||||
from .management.commands import dance
|
||||
|
||||
@ -401,11 +400,8 @@ class CommandTests(SimpleTestCase):
|
||||
self.assertIn("bar", out.getvalue())
|
||||
|
||||
def test_subparser_invalid_option(self):
|
||||
if PY314:
|
||||
msg = "invalid choice: 'test' (choose from foo)"
|
||||
else:
|
||||
msg = "invalid choice: 'test' (choose from 'foo')"
|
||||
with self.assertRaisesMessage(CommandError, msg):
|
||||
msg = r"invalid choice: 'test' \(choose from '?foo'?\)"
|
||||
with self.assertRaisesRegex(CommandError, msg):
|
||||
management.call_command("subparser", "test", 12)
|
||||
msg = "Error: the following arguments are required: subcommand"
|
||||
with self.assertRaisesMessage(CommandError, msg):
|
||||
|
Loading…
Reference in New Issue
Block a user