2 This plugin provides assert introspection. When the plugin is enabled
3 and a test failure occurs, the traceback is displayed with extra context
4 around the line in which the exception was raised. Simple variable
5 substitution is also performed in the context output to provide more
9 from nose.plugins import Plugin
10 from nose.inspector import inspect_traceback
12 class FailureDetail(Plugin):
14 Plugin that provides extra information in tracebacks of test failures.
16 score = 600 # before capture
18 def options(self, parser, env):
19 """Register commmandline options.
22 "-d", "--detailed-errors", "--failure-detail",
24 default=env.get('NOSE_DETAILED_ERRORS'),
25 dest="detailedErrors", help="Add detail to error"
26 " output by attempting to evaluate failed"
27 " asserts [NOSE_DETAILED_ERRORS]")
29 def configure(self, options, conf):
32 if not self.can_configure:
34 self.enabled = options.detailedErrors
37 def formatFailure(self, test, err):
38 """Add detail from traceback inspection to error message of a failure.
41 tbinfo = inspect_traceback(tb)
43 return (ec, '\n'.join([str(ev), tbinfo]), tb)