1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
<html>
<head>
<title>nose: builtin plugin: debug</title>
<link rel="stylesheet" href="site.css" type="text/css"></link>
</head>
<body>
<div id="menu">
<p>This document covers nose version <b>0.11.0</b></p>
<p>Last update: <b>Mon Sep 1 12:17:45 2008</b></p>
<h2>Plugins</h2><ul><li><a href="plugin_attrib.html">Builtin Plugin: attrib</a></li><li><a href="plugin_capture.html">Builtin Plugin: capture</a></li><li><a href="plugin_cover.html">Builtin Plugin: cover</a></li><li><a href="plugin_debug.html">Builtin Plugin: debug</a></li><li><a href="plugin_deprecated.html">Builtin Plugin: deprecated</a></li><li><a href="plugin_doctests.html">Builtin Plugin: doctests</a></li><li><a href="plugin_failuredetail.html">Builtin Plugin: failuredetail</a></li><li><a href="plugin_isolate.html">Builtin Plugin: isolate</a></li><li><a href="plugin_logcapture.html">Builtin Plugin: logcapture</a></li><li><a href="plugin_multiprocess.html">Builtin Plugin: multiprocess</a></li><li><a href="plugin_prof.html">Builtin Plugin: prof</a></li><li><a href="plugin_skip.html">Builtin Plugin: skip</a></li><li><a href="plugin_testid.html">Builtin Plugin: testid</a></li><li><a href="error_class_plugin.html">ErrorClass Plugins</a></li><li><a href="plugin_interface.html">Plugin Interface</a></li><li><a href="writing_plugins.html">Writing Plugins</a></li></ul><h2>Modules</h2><ul><li><a href="module_nose.case.html">Module: nose.case</a></li><li><a href="module_nose.commands.html">Module: nose.commands</a></li><li><a href="module_nose.config.html">Module: nose.config</a></li><li><a href="module_nose.core.html">Module: nose.core</a></li><li><a href="module_nose.exc.html">Module: nose.exc</a></li><li><a href="module_nose.failure.html">Module: nose.failure</a></li><li><a href="module_nose.importer.html">Module: nose.importer</a></li><li><a href="module_nose.inspector.html">Module: nose.inspector</a></li><li><a href="module_nose.loader.html">Module: nose.loader</a></li><li><a href="module_nose.plugins.manager.html">Module: nose.plugins.manager</a></li><li><a href="module_nose.plugins.plugintest.html">Module: nose.plugins.plugintest</a></li><li><a href="module_nose.proxy.html">Module: nose.proxy</a></li><li><a href="module_nose.result.html">Module: nose.result</a></li><li><a href="module_nose.selector.html">Module: nose.selector</a></li><li><a href="module_nose.suite.html">Module: nose.suite</a></li><li><a href="module_nose.tools.html">Module: nose.tools</a></li><li><a href="module_nose.twistedtools.html">Module: nose.twistedtools</a></li><li><a href="module_nose.util.html">Module: nose.util</a></li></ul><h2>Plugin Examples</h2><ul><li><a href="doctest_fixtures.html">Doctest Fixtures</a></li><li><a href="unwanted_package.html">Excluding Unwanted Packages</a></li><li><a href="errorclass_failure.html">Failure of Errorclasses</a></li><li><a href="imported_tests.html">Importing Tests</a></li><li><a href="empty_plugin.html">Minimal plugin</a></li><li><a href="multiprocess.html">Parallel Testing with nose</a></li><li><a href="restricted_plugin_options.html">Restricted Plugin Managers</a></li><li><a href="init_plugin.html">Running Initialization Code Before the Test Run</a></li><li><a href="selector_plugin.html">Using a Custom Selector</a></li><li><a href="plugin_exceptions.html">When Plugins Fail</a></li><li><a href="plugintest_environment.html">nose.plugins.plugintest, os.environ and sys.argv</a></li></ul>
</div>
<div id="main">
<h1>nose: builtin plugin: debug</h1>
<p>This plugin provides --pdb and --pdb-failures options that cause the
test runner to drop into pdb if it encounters an error or failure,
respectively.</p>
<h2>Plugin Methods Implemented</h2>
<p>This plugin implements the following plugin interface methods:</p>
<ul><li><a href="plugin_interface.html#addError">addError</a></li><li><a href="plugin_interface.html#addFailure">addFailure</a></li><li><a href="plugin_interface.html#configure">configure</a></li><li><a href="plugin_interface.html#options">options</a></li></ul>
<h2>Commandline Options</h2>
<p>This plugin adds the following commandline options:</p>
<pre>Options:
--pdb Drop into debugger on errors
--pdb-failures Drop into debugger on failures
</pre>
<h2>Source</h2>
<div class="highlight"><pre><span class="sd">"""</span>
<span class="sd">This plugin provides --pdb and --pdb-failures options that cause the</span>
<span class="sd">test runner to drop into pdb if it encounters an error or failure,</span>
<span class="sd">respectively.</span>
<span class="sd">"""</span>
<span class="k">import</span> <span class="nn">os</span>
<span class="k">import</span> <span class="nn">pdb</span>
<span class="k">from</span> <span class="nn">nose.plugins.base</span> <span class="k">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">Pdb</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Provides --pdb and --pdb-failures options that cause the test runner to</span>
<span class="sd"> drop into pdb if it encounters an error or failure, respectively.</span>
<span class="sd"> """</span>
<span class="n">enabled_for_errors</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">enabled_for_failures</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">score</span> <span class="o">=</span> <span class="mf">5</span> <span class="c"># run last, among builtins</span>
<span class="k">def</span> <span class="nf">options</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parser</span><span class="p">,</span> <span class="n">env</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">):</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span>
<span class="s">"--pdb"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">"store_true"</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s">"debugErrors"</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="n">env</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'NOSE_PDB'</span><span class="p">,</span> <span class="bp">False</span><span class="p">),</span>
<span class="n">help</span><span class="o">=</span><span class="s">"Drop into debugger on errors"</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span>
<span class="s">"--pdb-failures"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">"store_true"</span><span class="p">,</span>
<span class="n">dest</span><span class="o">=</span><span class="s">"debugFailures"</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="n">env</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'NOSE_PDB_FAILURES'</span><span class="p">,</span> <span class="bp">False</span><span class="p">),</span>
<span class="n">help</span><span class="o">=</span><span class="s">"Drop into debugger on failures"</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">conf</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span> <span class="o">=</span> <span class="n">conf</span>
<span class="bp">self</span><span class="o">.</span><span class="n">enabled</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">debugErrors</span> <span class="ow">or</span> <span class="n">options</span><span class="o">.</span><span class="n">debugFailures</span>
<span class="bp">self</span><span class="o">.</span><span class="n">enabled_for_errors</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">debugErrors</span>
<span class="bp">self</span><span class="o">.</span><span class="n">enabled_for_failures</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">debugFailures</span>
<span class="k">def</span> <span class="nf">addError</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="n">err</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">enabled_for_errors</span><span class="p">:</span>
<span class="k">return</span>
<span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">err</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">addFailure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">test</span><span class="p">,</span> <span class="n">err</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">enabled_for_failures</span><span class="p">:</span>
<span class="k">return</span>
<span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">err</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">debug</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">err</span><span class="p">):</span>
<span class="k">import</span> <span class="nn">sys</span>
<span class="n">ec</span><span class="p">,</span> <span class="n">ev</span><span class="p">,</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">err</span>
<span class="n">stdout</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">__stdout__</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">pdb</span><span class="o">.</span><span class="n">post_mortem</span><span class="p">(</span><span class="n">tb</span><span class="p">)</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span> <span class="o">=</span> <span class="n">stdout</span>
</pre></div>
</div>
<script src="http://www.google-analytics.com/urchin.js"
type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2236166-1";
urchinTracker();
</script>
</body>
</html>
|