diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2022-01-04 13:02:14 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-06 17:29:32 +0100 |
| commit | c67e1cf44f17c36139e25b1eae92216cb8baad77 (patch) | |
| tree | cb739fa75539adcbde1d73b86038c39a51cae046 /django/test | |
| parent | bc174e6ea0ce676c5a7f467bda9739e6ef6b6186 (diff) | |
Refs #33348 -- Deprecated passing errors=None to SimpleTestCase.assertFormError()/assertFormsetErrors().
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/testcases.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index 9759680f0f..1344d550a9 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -6,6 +6,7 @@ import posixpath import sys import threading import unittest +import warnings from collections import Counter from contextlib import contextmanager from copy import copy, deepcopy @@ -41,6 +42,7 @@ from django.test.utils import ( CaptureQueriesContext, ContextList, compare_xml, modify_settings, override_settings, ) +from django.utils.deprecation import RemovedInDjango50Warning from django.utils.functional import classproperty from django.utils.version import PY310 from django.views.static import serve @@ -50,13 +52,8 @@ __all__ = ('TestCase', 'TransactionTestCase', def to_list(value): - """ - Put value into a list if it's not already one. Return an empty list if - value is None. - """ - if value is None: - value = [] - elif not isinstance(value, list): + """Put value into a list if it's not already one.""" + if not isinstance(value, list): value = [value] return value @@ -493,10 +490,18 @@ class SimpleTestCase(unittest.TestCase): msg_prefix += ": " # Put context(s) into a list to simplify processing. - contexts = to_list(response.context) + contexts = [] if response.context is None else to_list(response.context) if not contexts: self.fail(msg_prefix + "Response did not use any contexts to render the response") + if errors is None: + warnings.warn( + 'Passing errors=None to assertFormError() is deprecated, use ' + 'errors=[] instead.', + RemovedInDjango50Warning, + stacklevel=2, + ) + errors = [] # Put error(s) into a list to simplify processing. errors = to_list(errors) @@ -556,11 +561,19 @@ class SimpleTestCase(unittest.TestCase): msg_prefix += ": " # Put context(s) into a list to simplify processing. - contexts = to_list(response.context) + contexts = [] if response.context is None else to_list(response.context) if not contexts: self.fail(msg_prefix + 'Response did not use any contexts to ' 'render the response') + if errors is None: + warnings.warn( + 'Passing errors=None to assertFormsetError() is deprecated, ' + 'use errors=[] instead.', + RemovedInDjango50Warning, + stacklevel=2, + ) + errors = [] # Put error(s) into a list to simplify processing. errors = to_list(errors) |
