Skip to content

Commit

Permalink
Fixed #25190 -- Deprecated callable_obj parameter to assertRaisesMess…
Browse files Browse the repository at this point in the history
…age().

Thanks Aymeric Augustin for review.
  • Loading branch information
timgraham committed Jul 30, 2015
1 parent 635ffc3 commit d27e0f0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions django/test/testcases.py
Expand Up @@ -618,6 +618,10 @@ def assertRaisesMessage(self, expected_exception, expected_message, *args, **kwa
# callable_obj was a documented kwarg in Django 1.8 and older.
callable_obj = kwargs.pop('callable_obj', None)
if callable_obj:
warnings.warn(
'The callable_obj kwarg is deprecated. Pass the callable '
'as a positional argument instead.', RemovedInDjango20Warning
)
args = (callable_obj,) + args
return six.assertRaisesRegex(self, expected_exception,
re.escape(expected_message), *args, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions docs/internals/deprecation.txt
Expand Up @@ -89,6 +89,9 @@ details on these changes.

* The ``current_app`` parameter to the ``contrib.auth`` views will be removed.

* The ``callable_obj`` keyword argument to
``SimpleTestCase.assertRaisesMessage()`` will be removed.

.. _deprecation-removed-in-1.10:

1.10
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/1.9.txt
Expand Up @@ -1077,6 +1077,10 @@ Miscellaneous
* ``django.template.loaders.eggs.Loader`` is deprecated as distributing
applications as eggs is not recommended.

* The ``callable_obj`` keyword argument to
``SimpleTestCase.assertRaisesMessage()`` is deprecated. Pass the callable as
a positional argument instead.

.. removed-features-1.9:

Features removed in 1.9
Expand Down
5 changes: 5 additions & 0 deletions docs/topics/testing/tools.txt
Expand Up @@ -1364,6 +1364,11 @@ your test suite.
with self.assertRaisesMessage(ValueError, 'invalid literal for int()'):
int('a')

.. deprecated:: 1.9

Passing ``callable`` as a keyword argument called ``callable_obj`` is
deprecated. Pass the callable as a positional argument instead.

.. method:: SimpleTestCase.assertFieldOutput(fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value='')

Asserts that a form field behaves correctly with various inputs.
Expand Down
18 changes: 16 additions & 2 deletions tests/test_utils/tests.py
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

import unittest
import warnings

from django.conf.urls import url
from django.contrib.staticfiles.finders import get_finder, get_finders
Expand All @@ -13,12 +14,14 @@
from django.http import HttpResponse
from django.template.loader import render_to_string
from django.test import (
SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature,
SimpleTestCase, TestCase, ignore_warnings, skipIfDBFeature,
skipUnlessDBFeature,
)
from django.test.html import HTMLParseError, parse_html
from django.test.utils import CaptureQueriesContext, override_settings
from django.utils import six
from django.utils._os import abspathu
from django.utils.deprecation import RemovedInDjango20Warning

from .models import Car, Person, PossessedCar
from .views import empty_response
Expand Down Expand Up @@ -752,11 +755,22 @@ def func1():
raise ValueError("[.*x+]y?")
self.assertRaisesMessage(ValueError, "[.*x+]y?", func1)

@ignore_warnings(category=RemovedInDjango20Warning)
def test_callable_obj_param(self):
# callable_obj was a documented kwarg in Django 1.8 and older.
def func1():
raise ValueError("[.*x+]y?")
self.assertRaisesMessage(ValueError, "[.*x+]y?", callable_obj=func1)

with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
self.assertRaisesMessage(ValueError, "[.*x+]y?", callable_obj=func1)

self.assertEqual(len(warns), 1)
self.assertEqual(
str(warns[0].message),
'The callable_obj kwarg is deprecated. Pass the callable '
'as a positional argument instead.'
)


class AssertFieldOutputTests(SimpleTestCase):
Expand Down

0 comments on commit d27e0f0

Please sign in to comment.