summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-05-09 19:13:05 -0400
committerTim Graham <timograham@gmail.com>2015-06-09 16:14:49 -0400
commit207da07d5988dc80439a10810ba28fc1fba42fe3 (patch)
tree04aea760f44c2f3594e91408c22d1fcc4639435d
parent7ae53e7480ef6835f56aa36fb4eff583e33cdcdd (diff)
downloaddjango-207da07d5988dc80439a10810ba28fc1fba42fe3.tar.gz
[1.7.x] Fixed #24903 -- Fixed assertRaisesMessage on Python 2.7.10.
A regression found in in Python 2.7.10 rc1 wasn't reverted for the final release: https://bugs.python.org/issue24134 Backport of two commits from master: * c2bc1cefdcbbf074408f4a4cace88b315cf9d652 * e89c3a46035e9fe17c373a6c9cd63b9fd631d596
-rw-r--r--django/test/testcases.py14
-rw-r--r--docs/releases/1.7.9.txt3
-rw-r--r--tests/test_utils/tests.py6
3 files changed, 18 insertions, 5 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 61b206dd93..fff05064e4 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -558,8 +558,7 @@ class SimpleTestCase(unittest.TestCase):
msg_prefix + "Template '%s' was used unexpectedly in rendering"
" the response" % template_name)
- def assertRaisesMessage(self, expected_exception, expected_message,
- callable_obj=None, *args, **kwargs):
+ def assertRaisesMessage(self, expected_exception, expected_message, *args, **kwargs):
"""
Asserts that the message in a raised exception matches the passed
value.
@@ -567,12 +566,17 @@ class SimpleTestCase(unittest.TestCase):
Args:
expected_exception: Exception class expected to be raised.
expected_message: expected error message string value.
- callable_obj: Function to be called.
- args: Extra args.
+ args: Function to be called and extra positional args.
kwargs: Extra kwargs.
"""
+ # callable_obj was a documented kwarg in older version of Django, but
+ # had to be removed due to a bad fix for http://bugs.python.org/issue24134
+ # inadvertently making its way into Python 2.7.10.
+ callable_obj = kwargs.pop('callable_obj', None)
+ if callable_obj:
+ args = (callable_obj,) + args
return six.assertRaisesRegex(self, expected_exception,
- re.escape(expected_message), callable_obj, *args, **kwargs)
+ re.escape(expected_message), *args, **kwargs)
def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
field_kwargs=None, empty_value=''):
diff --git a/docs/releases/1.7.9.txt b/docs/releases/1.7.9.txt
index bca875803c..903464a361 100644
--- a/docs/releases/1.7.9.txt
+++ b/docs/releases/1.7.9.txt
@@ -8,3 +8,6 @@ Django 1.7.9 fixes several bugs in 1.7.8.
* Prevented the loss of ``null``/``not null`` column properties during field
renaming of MySQL databases (:ticket:`24817`).
+
+* Fixed ``SimpleTestCase.assertRaisesMessage()`` on Python 2.7.10
+ (:ticket:`24903`).
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 365341d50f..1df0ca1859 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -605,6 +605,12 @@ class AssertRaisesMsgTest(SimpleTestCase):
raise ValueError("[.*x+]y?")
self.assertRaisesMessage(ValueError, "[.*x+]y?", func1)
+ def test_callable_obj_param(self):
+ # callable_obj was a documented kwarg in older version of Django.
+ def func1():
+ raise ValueError("[.*x+]y?")
+ self.assertRaisesMessage(ValueError, "[.*x+]y?", callable_obj=func1)
+
class AssertFieldOutputTests(SimpleTestCase):