From d4c9dab74bc29c240c33879a1167e5fd0971c7bc Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 15 Feb 2022 10:14:19 +0100 Subject: [PATCH] Refs #33348 -- Fixed SimpleTestCase.assertFormError() error message raised for unbound forms. --- django/test/testcases.py | 2 +- tests/test_utils/tests.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 1acc39fd761..5533c01db45 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -566,7 +566,7 @@ class SimpleTestCase(unittest.TestCase): def _assert_form_error(self, form, field, errors, msg_prefix, form_repr): if not form.is_bound: self.fail( - f"{msg_prefix} The {form_repr} is not bound, it will never have any " + f"{msg_prefix}The {form_repr} is not bound, it will never have any " f"errors." ) diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 506773b7128..92778439ed6 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -1448,6 +1448,9 @@ class AssertFormErrorTests(SimpleTestCase): response = mock.Mock(context=[{"form": TestForm()}]) with self.assertRaisesMessage(AssertionError, msg): self.assertFormError(response, "form", "field", []) + msg_prefix = "Custom prefix" + with self.assertRaisesMessage(AssertionError, f"{msg_prefix}: {msg}"): + self.assertFormError(response, "form", "field", [], msg_prefix=msg_prefix) def test_empty_errors_valid_form(self): response = mock.Mock(context=[{"form": TestForm.valid()}])