This file is indexed.

/usr/share/doc/python-pytest-doc/html/usage.html is in python-pytest-doc 2.5.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Usage and Invocations</title>
    
    <link rel="stylesheet" href="_static/flasky.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '2.5.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="None" href="index.html" />
    <link rel="up" title="Getting started basics" href="overview.html" />
    <link rel="next" title="Good Integration Practises" href="goodpractises.html" />
    <link rel="prev" title="Installation and Getting Started" href="getting-started.html" />
   
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
  <link href='http://fonts.googleapis.com/css?family=Gudea|Gudea' rel='stylesheet' type='text/css'>

  </head>
  <body>
  
  

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="goodpractises.html" title="Good Integration Practises"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="getting-started.html" title="Installation and Getting Started"
             accesskey="P">previous</a> |</li>
        <li><a href="contents.html">pytest-2.5.1</a> &raquo;</li>
          <li><a href="overview.html" accesskey="U">Getting started basics</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="usage-and-invocations">
<span id="usage"></span><h1>Usage and Invocations<a class="headerlink" href="#usage-and-invocations" title="Permalink to this headline"></a></h1>
<div class="section" id="calling-pytest-through-python-m-pytest">
<span id="cmdline"></span><h2>Calling pytest through <tt class="docutils literal"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">pytest</span></tt><a class="headerlink" href="#calling-pytest-through-python-m-pytest" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span>New in version 2.0.</span></p>
</div>
<p>If you use Python-2.5 or later you can invoke testing through the
Python interpreter from the command line:</p>
<div class="highlight-python"><pre>python -m pytest [...]</pre>
</div>
<p>This is equivalent to invoking the command line script <tt class="docutils literal"><span class="pre">py.test</span> <span class="pre">[...]</span></tt>
directly.</p>
</div>
<div class="section" id="getting-help-on-version-option-names-environment-variables">
<h2>Getting help on version, option names, environment variables<a class="headerlink" href="#getting-help-on-version-option-names-environment-variables" title="Permalink to this headline"></a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">version</span>   <span class="c"># shows where pytest was imported from</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">fixtures</span>  <span class="c"># show available builtin function arguments</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">-</span><span class="n">h</span> <span class="o">|</span> <span class="o">--</span><span class="n">help</span> <span class="c"># show help on command line and config file options</span>
</pre></div>
</div>
</div>
<div class="section" id="stopping-after-the-first-or-n-failures">
<h2>Stopping after the first (or N) failures<a class="headerlink" href="#stopping-after-the-first-or-n-failures" title="Permalink to this headline"></a></h2>
<p>To stop the testing process after the first (N) failures:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">-</span><span class="n">x</span>            <span class="c"># stop after first failure</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">maxfail</span><span class="o">=</span><span class="mi">2</span>    <span class="c"># stop after two failures</span>
</pre></div>
</div>
</div>
<div class="section" id="specifying-tests-selecting-tests">
<h2>Specifying tests / selecting tests<a class="headerlink" href="#specifying-tests-selecting-tests" title="Permalink to this headline"></a></h2>
<p>Several test run options:</p>
<div class="highlight-python"><pre>py.test test_mod.py   # run tests in module
py.test somepath      # run all tests below somepath
py.test -k stringexpr # only run tests with names that match the
                      # the "string expression", e.g. "MyClass and not method"
                      # will select TestMyClass.test_something
                      # but not TestMyClass.test_method_simple</pre>
</div>
<p>Import &#8216;pkg&#8217; and use its filesystem location to find and run tests:</p>
<div class="highlight-python"><pre>py.test --pyargs pkg # run all tests found below directory of pypkg</pre>
</div>
</div>
<div class="section" id="modifying-python-traceback-printing">
<h2>Modifying Python traceback printing<a class="headerlink" href="#modifying-python-traceback-printing" title="Permalink to this headline"></a></h2>
<p>Examples for modifying traceback printing:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">showlocals</span> <span class="c"># show local variables in tracebacks</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">-</span><span class="n">l</span>           <span class="c"># show local variables (shortcut)</span>

<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="nb">long</span>    <span class="c"># the default informative traceback formatting</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">native</span>  <span class="c"># the Python standard library formatting</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">short</span>   <span class="c"># a shorter traceback format</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">line</span>    <span class="c"># only one line per failure</span>
</pre></div>
</div>
</div>
<div class="section" id="dropping-to-pdb-python-debugger-on-failures">
<h2>Dropping to PDB (Python Debugger) on failures<a class="headerlink" href="#dropping-to-pdb-python-debugger-on-failures" title="Permalink to this headline"></a></h2>
<p>Python comes with a builtin Python debugger called <a class="reference external" href="http://docs.python.org/library/pdb.html">PDB</a>.  <tt class="docutils literal"><span class="pre">py.test</span></tt>
allows one to drop into the PDB prompt via a command line option:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">pdb</span>
</pre></div>
</div>
<p>This will invoke the Python debugger on every failure.  Often you might
only want to do this for the first failing test to understand a certain
failure situation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">-</span><span class="n">x</span> <span class="o">--</span><span class="n">pdb</span>   <span class="c"># drop to PDB on first failure, then end test session</span>
<span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">pdb</span> <span class="o">--</span><span class="n">maxfail</span><span class="o">=</span><span class="mi">3</span>  <span class="c"># drop to PDB for the first three failures</span>
</pre></div>
</div>
</div>
<div class="section" id="setting-a-breakpoint-aka-set-trace">
<h2>Setting a breakpoint / aka <tt class="docutils literal"><span class="pre">set_trace()</span></tt><a class="headerlink" href="#setting-a-breakpoint-aka-set-trace" title="Permalink to this headline"></a></h2>
<p>If you want to set a breakpoint and enter the <tt class="docutils literal"><span class="pre">pdb.set_trace()</span></tt> you
can use a helper:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">pytest</span>
<span class="k">def</span> <span class="nf">test_function</span><span class="p">():</span>
    <span class="o">...</span>
    <span class="n">pytest</span><span class="o">.</span><span class="n">set_trace</span><span class="p">()</span>    <span class="c"># invoke PDB debugger and tracing</span>
</pre></div>
</div>
<p>In previous versions you could only enter PDB tracing if
you disabled capturing on the command line via <tt class="docutils literal"><span class="pre">py.test</span> <span class="pre">-s</span></tt>.</p>
</div>
<div class="section" id="profiling-test-execution-duration">
<span id="durations"></span><h2>Profiling test execution duration<a class="headerlink" href="#profiling-test-execution-duration" title="Permalink to this headline"></a></h2>
<p>To get a list of the slowest 10 test durations:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">durations</span><span class="o">=</span><span class="mi">10</span>
</pre></div>
</div>
</div>
<div class="section" id="creating-junitxml-format-files">
<h2>Creating JUnitXML format files<a class="headerlink" href="#creating-junitxml-format-files" title="Permalink to this headline"></a></h2>
<p>To create result files which can be read by <a class="reference external" href="http://hudson-ci.org/">Hudson</a> or other Continuous
integration servers, use this invocation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">junitxml</span><span class="o">=</span><span class="n">path</span>
</pre></div>
</div>
<p>to create an XML file at <tt class="docutils literal"><span class="pre">path</span></tt>.</p>
</div>
<div class="section" id="creating-resultlog-format-files">
<h2>Creating resultlog format files<a class="headerlink" href="#creating-resultlog-format-files" title="Permalink to this headline"></a></h2>
<p>To create plain-text machine-readable result files you can issue:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">resultlog</span><span class="o">=</span><span class="n">path</span>
</pre></div>
</div>
<p>and look at the content at the <tt class="docutils literal"><span class="pre">path</span></tt> location.  Such files are used e.g.
by the <a class="reference external" href="http://buildbot.pypy.org/summary">PyPy-test</a> web page to show test results over several revisions.</p>
</div>
<div class="section" id="sending-test-report-to-online-pastebin-service">
<h2>Sending test report to online pastebin service<a class="headerlink" href="#sending-test-report-to-online-pastebin-service" title="Permalink to this headline"></a></h2>
<p><strong>Creating a URL for each test failure</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">pastebin</span><span class="o">=</span><span class="n">failed</span>
</pre></div>
</div>
<p>This will submit test run information to a remote Paste service and
provide a URL for each failure.  You may select tests as usual or add
for example <tt class="docutils literal"><span class="pre">-x</span></tt> if you only want to send one particular failure.</p>
<p><strong>Creating a URL for a whole test session log</strong>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">--</span><span class="n">pastebin</span><span class="o">=</span><span class="nb">all</span>
</pre></div>
</div>
<p>Currently only pasting to the <a class="reference external" href="http://bpaste.net">http://bpaste.net</a> service is implemented.</p>
</div>
<div class="section" id="calling-pytest-from-python-code">
<span id="pytest-main-usage"></span><h2>Calling pytest from Python code<a class="headerlink" href="#calling-pytest-from-python-code" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span>New in version 2.0.</span></p>
</div>
<p>You can invoke <tt class="docutils literal"><span class="pre">py.test</span></tt> from Python code directly:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pytest</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
</pre></div>
</div>
<p>this acts as if you would call &#8220;py.test&#8221; from the command line.
It will not raise <tt class="docutils literal"><span class="pre">SystemExit</span></tt> but return the exitcode instead.
You can pass in options and arguments:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pytest</span><span class="o">.</span><span class="n">main</span><span class="p">([</span><span class="s">&#39;-x&#39;</span><span class="p">,</span> <span class="s">&#39;mytestdir&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>or pass in a string:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pytest</span><span class="o">.</span><span class="n">main</span><span class="p">(</span><span class="s">&quot;-x mytestdir&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>You can specify additional plugins to <tt class="docutils literal"><span class="pre">pytest.main</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># content of myinvoke.py</span>
<span class="kn">import</span> <span class="nn">pytest</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">pytest_sessionfinish</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">print</span><span class="p">(</span><span class="s">&quot;*** test run reporting finishing&quot;</span><span class="p">)</span>

<span class="n">pytest</span><span class="o">.</span><span class="n">main</span><span class="p">(</span><span class="s">&quot;-qq&quot;</span><span class="p">,</span> <span class="n">plugins</span><span class="o">=</span><span class="p">[</span><span class="n">MyPlugin</span><span class="p">()])</span>
</pre></div>
</div>
<p>Running it will show that <tt class="docutils literal"><span class="pre">MyPlugin</span></tt> was added and its
hook was invoked:</p>
<div class="highlight-python"><pre>$ python myinvoke.py
*** test run reporting finishing</pre>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper"><h3><a href="contents.html">Table Of Contents</a></h3>

<ul>
  <li><a href="index.html">Home</a></li>
  <li><a href="contents.html">Contents</a></li>
  <li><a href="getting-started.html">Install</a></li>
  <li><a href="example/index.html">Examples</a></li>
  <li><a href="customize.html">Customize</a></li>
  <li><a href="contact.html">Contact</a></li>
  <li><a href="talks.html">Talks/Posts</a></li>
  <li><a href="changelog.html">Changelog</a></li>
</ul>
  <hr>
  <ul>
<li><a class="reference internal" href="#">Usage and Invocations</a><ul>
<li><a class="reference internal" href="#calling-pytest-through-python-m-pytest">Calling pytest through <tt class="docutils literal"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">pytest</span></tt></a></li>
<li><a class="reference internal" href="#getting-help-on-version-option-names-environment-variables">Getting help on version, option names, environment variables</a></li>
<li><a class="reference internal" href="#stopping-after-the-first-or-n-failures">Stopping after the first (or N) failures</a></li>
<li><a class="reference internal" href="#specifying-tests-selecting-tests">Specifying tests / selecting tests</a></li>
<li><a class="reference internal" href="#modifying-python-traceback-printing">Modifying Python traceback printing</a></li>
<li><a class="reference internal" href="#dropping-to-pdb-python-debugger-on-failures">Dropping to PDB (Python Debugger) on failures</a></li>
<li><a class="reference internal" href="#setting-a-breakpoint-aka-set-trace">Setting a breakpoint / aka <tt class="docutils literal"><span class="pre">set_trace()</span></tt></a></li>
<li><a class="reference internal" href="#profiling-test-execution-duration">Profiling test execution duration</a></li>
<li><a class="reference internal" href="#creating-junitxml-format-files">Creating JUnitXML format files</a></li>
<li><a class="reference internal" href="#creating-resultlog-format-files">Creating resultlog format files</a></li>
<li><a class="reference internal" href="#sending-test-report-to-online-pastebin-service">Sending test report to online pastebin service</a></li>
<li><a class="reference internal" href="#calling-pytest-from-python-code">Calling pytest from Python code</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
  <li><a href="contents.html">Documentation overview</a><ul>
  <li><a href="overview.html">Getting started basics</a><ul>
      <li>Previous: <a href="getting-started.html" title="previous chapter">Installation and Getting Started</a></li>
      <li>Next: <a href="goodpractises.html" title="next chapter">Good Integration Practises</a></li>
  </ul></li>
  </ul></li>
</ul><h3>Useful Links</h3>
<ul>
  <li><a href="index.html">The pytest Website</a></li>
  <li><a href="https://pypi.python.org/pypi/pytest">pytest @ PyPI</a></li>
  <li><a href="https://bitbucket.org/hpk42/pytest/">pytest @ Bitbucket</a></li>
  <li><a href="https://github.com/hpk42/pytest/">pytest @ github</a></li>
  <li><a href="https://bitbucket.org/hpk42/pytest/issues?status=new&status=open">Issue Tracker</a></li>
  <li><a href="http://pytest.org/latest/pytest.pdf">PDF Documentation</a>
</ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>

  <div class="footer">
    &copy; Copyright 2012, holger krekel.
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  

  </body>
</html>