mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
[5.1.x] 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+.. Backport of fc22fdd34f1e55adde161f5f2dca8db90bbfce80 from main.
This commit is contained in:
parent
c5ddc8550c
commit
b57a8395b5
@ -2304,8 +2304,8 @@ class Discovery(SimpleTestCase):
|
|||||||
class CommandDBOptionChoiceTests(SimpleTestCase):
|
class CommandDBOptionChoiceTests(SimpleTestCase):
|
||||||
def test_invalid_choice_db_option(self):
|
def test_invalid_choice_db_option(self):
|
||||||
expected_error = (
|
expected_error = (
|
||||||
"Error: argument --database: invalid choice: "
|
r"Error: argument --database: invalid choice: 'deflaut' "
|
||||||
"'deflaut' (choose from 'default', 'other')"
|
r"\(choose from '?default'?, '?other'?\)"
|
||||||
)
|
)
|
||||||
args = [
|
args = [
|
||||||
"changepassword",
|
"changepassword",
|
||||||
@ -2326,7 +2326,7 @@ class CommandDBOptionChoiceTests(SimpleTestCase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
with self.assertRaisesMessage(CommandError, expected_error):
|
with self.assertRaisesRegex(CommandError, expected_error):
|
||||||
call_command(arg, "--database", "deflaut", verbosity=0)
|
call_command(arg, "--database", "deflaut", verbosity=0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -400,8 +400,8 @@ class CommandTests(SimpleTestCase):
|
|||||||
self.assertIn("bar", out.getvalue())
|
self.assertIn("bar", out.getvalue())
|
||||||
|
|
||||||
def test_subparser_invalid_option(self):
|
def test_subparser_invalid_option(self):
|
||||||
msg = "invalid choice: 'test' (choose from 'foo')"
|
msg = r"invalid choice: 'test' \(choose from '?foo'?\)"
|
||||||
with self.assertRaisesMessage(CommandError, msg):
|
with self.assertRaisesRegex(CommandError, msg):
|
||||||
management.call_command("subparser", "test", 12)
|
management.call_command("subparser", "test", 12)
|
||||||
msg = "Error: the following arguments are required: subcommand"
|
msg = "Error: the following arguments are required: subcommand"
|
||||||
with self.assertRaisesMessage(CommandError, msg):
|
with self.assertRaisesMessage(CommandError, msg):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user