Skip to content

Commit b57a839

Browse files
tainarapalmeirasarahboyce
authored andcommitted
[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 fc22fdd from main.
1 parent c5ddc85 commit b57a839

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

tests/admin_scripts/tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,8 +2304,8 @@ def test_precedence(self):
23042304
class CommandDBOptionChoiceTests(SimpleTestCase):
23052305
def test_invalid_choice_db_option(self):
23062306
expected_error = (
2307-
"Error: argument --database: invalid choice: "
2308-
"'deflaut' (choose from 'default', 'other')"
2307+
r"Error: argument --database: invalid choice: 'deflaut' "
2308+
r"\(choose from '?default'?, '?other'?\)"
23092309
)
23102310
args = [
23112311
"changepassword",
@@ -2326,7 +2326,7 @@ def test_invalid_choice_db_option(self):
23262326
]
23272327

23282328
for arg in args:
2329-
with self.assertRaisesMessage(CommandError, expected_error):
2329+
with self.assertRaisesRegex(CommandError, expected_error):
23302330
call_command(arg, "--database", "deflaut", verbosity=0)
23312331

23322332

tests/user_commands/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ def test_subparser_dest_required_args(self):
400400
self.assertIn("bar", out.getvalue())
401401

402402
def test_subparser_invalid_option(self):
403-
msg = "invalid choice: 'test' (choose from 'foo')"
404-
with self.assertRaisesMessage(CommandError, msg):
403+
msg = r"invalid choice: 'test' \(choose from '?foo'?\)"
404+
with self.assertRaisesRegex(CommandError, msg):
405405
management.call_command("subparser", "test", 12)
406406
msg = "Error: the following arguments are required: subcommand"
407407
with self.assertRaisesMessage(CommandError, msg):

0 commit comments

Comments
 (0)