diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2022-02-14 08:42:27 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-14 08:43:46 +0100 |
| commit | 7986028e3fbc9f84fca5a25a03cecfbc85ca5ce7 (patch) | |
| tree | 817ce34252ceb1765e4118d1c8c28e93f4f00c8f /django/test | |
| parent | cdd4ff67d23b80741047eaf6b180dc67a782dfbd (diff) | |
Refs #33348 -- Made SimpleTestCase.assertFormError()/assertFormsetErrors() raise an error for unbound forms/formsets.
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/testcases.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index 14416807be..0d24bf0d40 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -595,6 +595,12 @@ class SimpleTestCase(unittest.TestCase): for i, context in enumerate(contexts): if form not in context: continue + if not context[form].is_bound: + form_repr = repr(context[form]) + self.fail( + f"{msg_prefix}The form {form_repr} is not bound, it will never " + f"have any errors." + ) found_form = True for err in errors: if field: @@ -680,6 +686,12 @@ class SimpleTestCase(unittest.TestCase): for i, context in enumerate(contexts): if formset not in context or not hasattr(context[formset], "forms"): continue + if not context[formset].is_bound: + formset_repr = repr(context[formset]) + self.fail( + f"{msg_prefix}The formset {formset_repr} is not bound, it will " + f"never have any errors." + ) found_formset = True for err in errors: if field is not None: |
