summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2009-03-31 19:59:14 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2009-03-31 19:59:14 (GMT)
commit65ff00559a1192bccb23b5af9abb54db361d9124 (patch)
tree4e98f118bd90d4ee6762fd6ba75d8f73a09be744
parent41448c58d25386b4040cebc9d8078fe1749365e6 (diff)
downloadcpython-65ff00559a1192bccb23b5af9abb54db361d9124.zip
cpython-65ff00559a1192bccb23b5af9abb54db361d9124.tar.gz
cpython-65ff00559a1192bccb23b5af9abb54db361d9124.tar.bz2
Issue an actual PendingDeprecationWarning for the TestCase.fail* methods.
Document the deprecation.
-rw-r--r--Doc/library/unittest.rst21
-rw-r--r--Lib/unittest.py26
2 files changed, 38 insertions, 9 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index d4ef248..a03982a 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -613,6 +613,9 @@ Test cases
Signal a test failure if *expr* is false; the explanation for the error
will be *msg* if given, otherwise it will be :const:`None`.
+ .. deprecated:: 2.7
+ :meth:`failUnless`.
+
.. method:: assertEqual(first, second[, msg])
failUnlessEqual(first, second[, msg])
@@ -632,6 +635,9 @@ Test cases
.. versionchanged:: 2.7
Added the automatic calling of type specific equality function.
+ .. deprecated:: 2.7
+ :meth:`failUnlessEqual`.
+
.. method:: assertNotEqual(first, second[, msg])
failIfEqual(first, second[, msg])
@@ -643,6 +649,9 @@ Test cases
default value for *msg* can be computed to include representations of both
*first* and *second*.
+ .. deprecated:: 2.7
+ :meth:`failIfEqual`.
+
.. method:: assertAlmostEqual(first, second[, places[, msg]])
failUnlessAlmostEqual(first, second[, places[, msg]])
@@ -656,6 +665,9 @@ Test cases
compare equal, the test will fail with the explanation given by *msg*, or
:const:`None`.
+ .. deprecated:: 2.7
+ :meth:`failUnlessAlmostEqual`.
+
.. method:: assertNotAlmostEqual(first, second[, places[, msg]])
failIfAlmostEqual(first, second[, places[, msg]])
@@ -669,6 +681,9 @@ Test cases
compare equal, the test will fail with the explanation given by *msg*, or
:const:`None`.
+ .. deprecated:: 2.7
+ :meth:`failIfAlmostEqual`.
+
.. method:: assertGreater(first, second, msg=None)
assertGreaterEqual(first, second, msg=None)
@@ -808,6 +823,9 @@ Test cases
.. versionchanged:: 2.7
Added the ability to use :meth:`assertRaises` as a context manager.
+ .. deprecated:: 2.7
+ :meth:`failUnlessRaises`.
+
.. method:: assertRaisesRegexp(exception, regexp[, callable, ...])
@@ -849,6 +867,9 @@ Test cases
This signals a test failure if *expr* is true, with *msg* or :const:`None`
for the error message.
+ .. deprecated:: 2.7
+ :meth:`failIf`.
+
.. method:: fail([msg])
diff --git a/Lib/unittest.py b/Lib/unittest.py
index ba6a0f9..9718e86 100644
--- a/Lib/unittest.py
+++ b/Lib/unittest.py
@@ -54,6 +54,7 @@ import sys
import time
import traceback
import types
+import warnings
##############################################################################
# Exported classes and functions
@@ -574,15 +575,22 @@ class TestCase(object):
assert_ = assertTrue
# These fail* assertion method names are pending deprecation and will
- # be a deprecation warning in 3.2; http://bugs.python.org/issue2578
- failUnlessEqual = assertEqual
- failIfEqual = assertNotEqual
- failUnlessAlmostEqual = assertAlmostEqual
- failIfAlmostEqual = assertNotAlmostEqual
- failUnless = assertTrue
- failUnlessRaises = assertRaises
- failIf = assertFalse
-
+ # be a DeprecationWarning in 3.2; http://bugs.python.org/issue2578
+ def __deprecate(original_func):
+ def deprecated_func(*args, **kwargs):
+ warnings.warn(
+ 'Please use {0} instead.'.format(original_func.__name__),
+ PendingDeprecationWarning, 2)
+ return original_func(*args, **kwargs)
+ return deprecated_func
+
+ failUnlessEqual = __deprecate(assertEqual)
+ failIfEqual = __deprecate(assertNotEqual)
+ failUnlessAlmostEqual = __deprecate(assertAlmostEqual)
+ failIfAlmostEqual = __deprecate(assertNotAlmostEqual)
+ failUnless = __deprecate(assertTrue)
+ failUnlessRaises = __deprecate(assertRaises)
+ failIf = __deprecate(assertFalse)
def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None):
"""An equality assertion for ordered sequences (like lists and tuples).