summaryrefslogtreecommitdiff
path: root/nose/plugins/errorclass.py
diff options
context:
space:
mode:
Diffstat (limited to 'nose/plugins/errorclass.py')
-rw-r--r--nose/plugins/errorclass.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/nose/plugins/errorclass.py b/nose/plugins/errorclass.py
index 51b20ed..d327194 100644
--- a/nose/plugins/errorclass.py
+++ b/nose/plugins/errorclass.py
@@ -29,7 +29,7 @@ into the tuples used by the error handling and reporting functions in
the result. This is an internal format and subject to change; you
should always use the declarative syntax for attaching ErrorClasses to
an ErrorClass plugin.
-
+
>>> TodoError.errorClasses # doctest: +ELLIPSIS
((<class ...Todo...>, ('todo', 'TODO', True)),)
@@ -42,7 +42,7 @@ Let's see the plugin in action. First some boilerplate.
... from unittest.runner import _WritelnDecorator
... except ImportError:
... from unittest import _WritelnDecorator
- ...
+ ...
>>> buf = _WritelnDecorator(sys.stdout)
Now define a test case that raises a Todo.
@@ -154,6 +154,7 @@ class ErrorClassPlugin(Plugin):
result.errorClasses[cls] = (storage, label, isfail)
def patchResult(self, result):
+ result.printLabel = print_label_patch(result)
result._orig_addError, result.addError = \
result.addError, add_error_patch(result)
result._orig_wasSuccessful, result.wasSuccessful = \
@@ -161,6 +162,9 @@ class ErrorClassPlugin(Plugin):
if hasattr(result, 'printErrors'):
result._orig_printErrors, result.printErrors = \
result.printErrors, print_errors_patch(result)
+ if hasattr(result, 'addSkip'):
+ result._orig_addSkip, result.addSkip = \
+ result.addSkip, add_skip_patch(result)
result.errorClasses = {}
@@ -181,6 +185,14 @@ def print_errors_patch(result):
TextTestResult.printErrors.im_func, result, result.__class__)
+def print_label_patch(result):
+ """Create a new printLabel method that prints errorClasses items
+ as well.
+ """
+ return instancemethod(
+ TextTestResult.printLabel.im_func, result, result.__class__)
+
+
def wassuccessful_patch(result):
"""Create a new wasSuccessful method that checks errorClasses for
exceptions that were put into other slots than error or failure
@@ -189,7 +201,15 @@ def wassuccessful_patch(result):
return instancemethod(
TextTestResult.wasSuccessful.im_func, result, result.__class__)
-
+
+def add_skip_patch(result):
+ """Create a new addSkip method to patch into a result instance
+ that delegates to addError.
+ """
+ return instancemethod(
+ TextTestResult.addSkip.im_func, result, result.__class__)
+
+
if __name__ == '__main__':
import doctest
doctest.testmod()