From 5064ddb4f9532cb2827744c052f277c39b74920a Mon Sep 17 00:00:00 2001 From: Tainara Palmeira Date: Mon, 28 Oct 2024 14:46:20 +0100 Subject: [PATCH] [5.0.x] Refs #35844 -- Expanded compatibility for expected error messages in command tests on Python 3.12. 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. --- tests/user_commands/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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):