2 This plugin provides ``--pdb`` and ``--pdb-failures`` options. The ``--pdb``
3 option will drop the test runner into pdb when it encounters an error. To
4 drop into pdb on failure, use ``--pdb-failures``.
8 from nose.plugins.base import Plugin
12 Provides --pdb and --pdb-failures options that cause the test runner to
13 drop into pdb if it encounters an error or failure, respectively.
15 enabled_for_errors = False
16 enabled_for_failures = False
17 score = 5 # run last, among builtins
19 def options(self, parser, env):
20 """Register commandline options.
23 "--pdb", action="store_true", dest="debugErrors",
24 default=env.get('NOSE_PDB', False),
25 help="Drop into debugger on errors")
27 "--pdb-failures", action="store_true",
29 default=env.get('NOSE_PDB_FAILURES', False),
30 help="Drop into debugger on failures")
32 def configure(self, options, conf):
33 """Configure which kinds of exceptions trigger plugin.
36 self.enabled = options.debugErrors or options.debugFailures
37 self.enabled_for_errors = options.debugErrors
38 self.enabled_for_failures = options.debugFailures
40 def addError(self, test, err):
41 """Enter pdb if configured to debug errors.
43 if not self.enabled_for_errors:
47 def addFailure(self, test, err):
48 """Enter pdb if configured to debug failures.
50 if not self.enabled_for_failures:
55 import sys # FIXME why is this import here?
58 sys.stdout = sys.__stdout__