summaryrefslogtreecommitdiff
path: root/Lib/unittest/case.py
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-02-22 23:28:32 +0000
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-02-22 23:28:32 +0000
commitae3db0a12b0c5ca42ea9fe54161d56c57269ea92 (patch)
tree5a636558ffc55d6f41efdece75cb2163056b4ce1 /Lib/unittest/case.py
parent4b81bc7fe6aad900cf2904c8a22a2c70a8b42659 (diff)
downloadcpython-git-ae3db0a12b0c5ca42ea9fe54161d56c57269ea92.tar.gz
Support for old TestResult object (unittest) with warnings when using unsupported features.
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r--Lib/unittest/case.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 8de36d7512..88d1bec889 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -249,6 +249,15 @@ class TestCase(object):
return "<%s testMethod=%s>" % \
(strclass(self.__class__), self._testMethodName)
+ def _addSkip(self, result, reason):
+ addSkip = getattr(result, 'addSkip', None)
+ if addSkip is not None:
+ addSkip(self, reason)
+ else:
+ warnings.warn("TestResult has no addSkip method, skips not reported",
+ RuntimeWarning, 2)
+ result.addSuccess(self)
+
def run(self, result=None):
orig_result = result
if result is None:
@@ -262,7 +271,7 @@ class TestCase(object):
if getattr(self.__class__, "__unittest_skip__", False):
# If the whole class was skipped.
try:
- result.addSkip(self, self.__class__.__unittest_skip_why__)
+ self._addSkip(result, self.__class__.__unittest_skip_why__)
finally:
result.stopTest(self)
return
@@ -272,7 +281,7 @@ class TestCase(object):
try:
self.setUp()
except SkipTest as e:
- result.addSkip(self, str(e))
+ self._addSkip(result, str(e))
except Exception:
result.addError(self, sys.exc_info())
else:
@@ -281,11 +290,23 @@ class TestCase(object):
except self.failureException:
result.addFailure(self, sys.exc_info())
except _ExpectedFailure as e:
- result.addExpectedFailure(self, e.exc_info)
+ addExpectedFailure = getattr(result, 'addExpectedFailure', None)
+ if addExpectedFailure is not None:
+ addExpectedFailure(self, e.exc_info)
+ else:
+ warnings.warn("TestResult has no addExpectedFailure method, reporting as passes",
+ RuntimeWarning)
+ result.addSuccess(self)
except _UnexpectedSuccess:
- result.addUnexpectedSuccess(self)
+ addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None)
+ if addUnexpectedSuccess is not None:
+ addUnexpectedSuccess(self)
+ else:
+ warnings.warn("TestResult has no addUnexpectedSuccess method, reporting as failures",
+ RuntimeWarning)
+ result.addFailure(self, sys.exc_info())
except SkipTest as e:
- result.addSkip(self, str(e))
+ self._addSkip(result, str(e))
except Exception:
result.addError(self, sys.exc_info())
else: