summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-03-07 20:22:12 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-03-07 20:22:12 (GMT)
commit53e8eeadd60ab7566d2bc29a51ce286a890dd14b (patch)
tree7dbc8ce24d555d524f41f6d582015e279b53d687 /Lib/unittest
parentfc8a1ed70e2586871e06cea60dfd25a96ed5a313 (diff)
downloadcpython-53e8eeadd60ab7566d2bc29a51ce286a890dd14b.zip
cpython-53e8eeadd60ab7566d2bc29a51ce286a890dd14b.tar.gz
cpython-53e8eeadd60ab7566d2bc29a51ce286a890dd14b.tar.bz2
Fix for potentials errors in constructing unittest failure messages. Plus skipped test methods no longer run setUp and tearDown (Issue 8059)
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py36
1 files changed, 23 insertions, 13 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index aacd67c..19b196c 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -45,14 +45,15 @@ def skip(reason):
Unconditionally skip a test.
"""
def decorator(test_item):
- if isinstance(test_item, type) and issubclass(test_item, TestCase):
- test_item.__unittest_skip__ = True
- test_item.__unittest_skip_why__ = reason
- return test_item
- @functools.wraps(test_item)
- def skip_wrapper(*args, **kwargs):
- raise SkipTest(reason)
- return skip_wrapper
+ if not (isinstance(test_item, type) and issubclass(test_item, TestCase)):
+ @functools.wraps(test_item)
+ def skip_wrapper(*args, **kwargs):
+ raise SkipTest(reason)
+ test_item = skip_wrapper
+
+ test_item.__unittest_skip__ = True
+ test_item.__unittest_skip_why__ = reason
+ return test_item
return decorator
def skipIf(condition, reason):
@@ -268,14 +269,18 @@ class TestCase(object):
self._resultForDoCleanups = result
result.startTest(self)
- if getattr(self.__class__, "__unittest_skip__", False):
- # If the whole class was skipped.
+
+ testMethod = getattr(self, self._testMethodName)
+ if (getattr(self.__class__, "__unittest_skip__", False) or
+ getattr(testMethod, "__unittest_skip__", False)):
+ # If the class or method was skipped.
try:
- self._addSkip(result, self.__class__.__unittest_skip_why__)
+ skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
+ or getattr(testMethod, '__unittest_skip_why__', ''))
+ self._addSkip(result, skip_why)
finally:
result.stopTest(self)
return
- testMethod = getattr(self, self._testMethodName)
try:
success = False
try:
@@ -386,7 +391,12 @@ class TestCase(object):
return msg or standardMsg
if msg is None:
return standardMsg
- return standardMsg + ' : ' + msg
+ try:
+ # don't switch to '{}' formatting in Python 2.X
+ # it changes the way unicode input is handled
+ return '%s : %s' % (standardMsg, msg)
+ except UnicodeDecodeError:
+ return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg))
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):