diff options
| author | Tainara Palmeira <tainarapalmeirag@gmail.com> | 2024-10-28 14:46:20 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-10-30 11:03:51 +0100 |
| commit | b57a8395b58ae47124efcc33455abc7d32553354 (patch) | |
| tree | da13f581d7d3051c07492804ae9a3844161d7372 | |
| parent | c5ddc8550c5834e8b1952445ebfb217563de128f (diff) | |
[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.
| -rw-r--r-- | tests/admin_scripts/tests.py | 6 | ||||
| -rw-r--r-- | tests/user_commands/tests.py | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 2e77f2c97a..6878da6f58 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -2304,8 +2304,8 @@ class Discovery(SimpleTestCase): class CommandDBOptionChoiceTests(SimpleTestCase): def test_invalid_choice_db_option(self): expected_error = ( - "Error: argument --database: invalid choice: " - "'deflaut' (choose from 'default', 'other')" + r"Error: argument --database: invalid choice: 'deflaut' " + r"\(choose from '?default'?, '?other'?\)" ) args = [ "changepassword", @@ -2326,7 +2326,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) diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index 65e176620d..2a1e904f3b 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -400,8 +400,8 @@ class CommandTests(SimpleTestCase): self.assertIn("bar", out.getvalue()) def test_subparser_invalid_option(self): - 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): |
