This file is indexed.

/usr/share/doc/python-pytest/html/usage.html is in python-pytest-doc 3.3.2-2.

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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!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 &#8212; pytest documentation</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:     '3.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </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="shortcut icon" href="_static/pytest1favi.ico"/>
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Using pytest with an existing test suite" href="existingtestsuite.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">

  </head>
  <body>
  
  
  


    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="existingtestsuite.html" title="Using pytest with an existing test suite"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="getting-started.html" title="Installation and Getting Started"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="contents.html">pytest-3.3</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <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 <code class="docutils literal"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">pytest</span></code><a class="headerlink" href="#calling-pytest-through-python-m-pytest" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.0.</span></p>
</div>
<p>You can invoke testing through the Python interpreter from the command line:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">pytest</span> <span class="p">[</span><span class="o">...</span><span class="p">]</span>
</pre></div>
</div>
<p>This is almost equivalent to invoking the command line script <code class="docutils literal"><span class="pre">pytest</span> <span class="pre">[...]</span></code>
directly, except that calling via <code class="docutils literal"><span class="pre">python</span></code> will also add the current directory to <code class="docutils literal"><span class="pre">sys.path</span></code>.</p>
</div>
<div class="section" id="possible-exit-codes">
<h2>Possible exit codes<a class="headerlink" href="#possible-exit-codes" title="Permalink to this headline"></a></h2>
<p>Running <code class="docutils literal"><span class="pre">pytest</span></code> can result in six different exit codes:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Exit code 0:</th><td class="field-body">All tests were collected and passed successfully</td>
</tr>
<tr class="field-even field"><th class="field-name">Exit code 1:</th><td class="field-body">Tests were collected and run but some of the tests failed</td>
</tr>
<tr class="field-odd field"><th class="field-name">Exit code 2:</th><td class="field-body">Test execution was interrupted by the user</td>
</tr>
<tr class="field-even field"><th class="field-name">Exit code 3:</th><td class="field-body">Internal error happened while executing tests</td>
</tr>
<tr class="field-odd field"><th class="field-name">Exit code 4:</th><td class="field-body">pytest command line usage error</td>
</tr>
<tr class="field-even field"><th class="field-name">Exit code 5:</th><td class="field-body">No tests were collected</td>
</tr>
</tbody>
</table>
</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-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">--</span><span class="n">version</span>   <span class="c1"># shows where pytest was imported from</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">fixtures</span>  <span class="c1"># show available builtin function arguments</span>
<span class="n">pytest</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="c1"># 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">
<span id="maxfail"></span><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-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">-</span><span class="n">x</span>            <span class="c1"># stop after first failure</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">maxfail</span><span class="o">=</span><span class="mi">2</span>    <span class="c1"># stop after two failures</span>
</pre></div>
</div>
</div>
<div class="section" id="specifying-tests-selecting-tests">
<span id="select-tests"></span><h2>Specifying tests / selecting tests<a class="headerlink" href="#specifying-tests-selecting-tests" title="Permalink to this headline"></a></h2>
<p>Pytest supports several ways to run and select tests from the command-line.</p>
<p><strong>Run tests in a module</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="n">test_mod</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p><strong>Run tests in a directory</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="n">testing</span><span class="o">/</span>
</pre></div>
</div>
<p><strong>Run tests by keyword expressions</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">-</span><span class="n">k</span> <span class="s2">&quot;MyClass and not method&quot;</span>
</pre></div>
</div>
<p>This will run tests which contain names that match the given <em>string expression</em>, which can
include Python operators that use filenames, class names and function names as variables.
The example above will run <code class="docutils literal"><span class="pre">TestMyClass.test_something</span></code>  but not <code class="docutils literal"><span class="pre">TestMyClass.test_method_simple</span></code>.</p>
<p id="nodeids"><strong>Run tests by node ids</strong></p>
<p>Each collected test is assigned a unique <code class="docutils literal"><span class="pre">nodeid</span></code> which consist of the module filename followed
by specifiers like class names, function names and parameters from parametrization, separated by <code class="docutils literal"><span class="pre">::</span></code> characters.</p>
<p>To run a specific test within a module:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="n">test_mod</span><span class="o">.</span><span class="n">py</span><span class="p">::</span><span class="n">test_func</span>
</pre></div>
</div>
<p>Another example specifying a test method in the command line:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="n">test_mod</span><span class="o">.</span><span class="n">py</span><span class="p">::</span><span class="n">TestClass</span><span class="p">::</span><span class="n">test_method</span>
</pre></div>
</div>
<p><strong>Run tests by marker expressions</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">-</span><span class="n">m</span> <span class="n">slow</span>
</pre></div>
</div>
<p>Will run all tests which are decorated with the <code class="docutils literal"><span class="pre">&#64;pytest.mark.slow</span></code> decorator.</p>
<p>For more information see <a class="reference internal" href="mark.html#mark"><span class="std std-ref">marks</span></a>.</p>
<p><strong>Run tests from packages</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">--</span><span class="n">pyargs</span> <span class="n">pkg</span><span class="o">.</span><span class="n">testing</span>
</pre></div>
</div>
<p>This will import <code class="docutils literal"><span class="pre">pkg.testing</span></code> and use its filesystem location to find and run tests from.</p>
</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-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">--</span><span class="n">showlocals</span> <span class="c1"># show local variables in tracebacks</span>
<span class="n">pytest</span> <span class="o">-</span><span class="n">l</span>           <span class="c1"># show local variables (shortcut)</span>

<span class="n">pytest</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">auto</span>    <span class="c1"># (default) &#39;long&#39; tracebacks for the first and last</span>
                     <span class="c1"># entry, but &#39;short&#39; style for the other entries</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">long</span>    <span class="c1"># exhaustive, informative traceback formatting</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">short</span>   <span class="c1"># shorter traceback format</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">line</span>    <span class="c1"># only one line per failure</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">native</span>  <span class="c1"># Python standard library formatting</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">tb</span><span class="o">=</span><span class="n">no</span>      <span class="c1"># no traceback at all</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">--full-trace</span></code> causes very long traces to be printed on error (longer
than <code class="docutils literal"><span class="pre">--tb=long</span></code>). It also ensures that a stack trace is printed on
<strong>KeyboardInterrupt</strong> (Ctrl+C).
This is very useful if the tests are taking too long and you interrupt them
with Ctrl+C to find out where the tests are <em>hanging</em>. By default no output
will be shown (because KeyboardInterrupt is caught by pytest). By using this
option you make sure a trace is shown.</p>
</div>
<div class="section" id="dropping-to-pdb-python-debugger-on-failures">
<span id="pdb-option"></span><h2>Dropping to <a class="reference external" href="http://docs.python.org/library/pdb.html">PDB</a> (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>.  <code class="docutils literal"><span class="pre">pytest</span></code>
allows one to drop into the <a class="reference external" href="http://docs.python.org/library/pdb.html">PDB</a> prompt via a command line option:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</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-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">-</span><span class="n">x</span> <span class="o">--</span><span class="n">pdb</span>   <span class="c1"># drop to PDB on first failure, then end test session</span>
<span class="n">pytest</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="c1"># drop to PDB for first three failures</span>
</pre></div>
</div>
<p>Note that on any failure the exception information is stored on
<code class="docutils literal"><span class="pre">sys.last_value</span></code>, <code class="docutils literal"><span class="pre">sys.last_type</span></code> and <code class="docutils literal"><span class="pre">sys.last_traceback</span></code>. In
interactive use, this allows one to drop into postmortem debugging with
any debug tool. One can also manually access the exception information,
for example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">last_traceback</span><span class="o">.</span><span class="n">tb_lineno</span>
<span class="go">42</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">last_value</span>
<span class="go">AssertionError(&#39;assert result == &quot;ok&quot;&#39;,)</span>
</pre></div>
</div>
</div>
<div class="section" id="setting-breakpoints">
<span id="breakpoints"></span><h2>Setting breakpoints<a class="headerlink" href="#setting-breakpoints" title="Permalink to this headline"></a></h2>
<p>To set a breakpoint in your code use the native Python <code class="docutils literal"><span class="pre">import</span> <span class="pre">pdb;pdb.set_trace()</span></code> call
in your code and pytest automatically disables its output capture for that test:</p>
<ul class="simple">
<li>Output capture in other tests is not affected.</li>
<li>Any prior test output that has already been captured and will be processed as
such.</li>
<li>Any later output produced within the same test will not be captured and will
instead get sent directly to <code class="docutils literal"><span class="pre">sys.stdout</span></code>. Note that this holds true even
for test output occurring after you exit the interactive <a class="reference external" href="http://docs.python.org/library/pdb.html">PDB</a> tracing session
and continue with the regular test run.</li>
</ul>
</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-default"><div class="highlight"><pre><span></span><span class="n">pytest</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://jenkins-ci.org/">Jenkins</a> or other Continuous
integration servers, use this invocation:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</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 <code class="docutils literal"><span class="pre">path</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.1.</span></p>
</div>
<p>To set the name of the root test suite xml item, you can configure the <code class="docutils literal"><span class="pre">junit_suite_name</span></code> option in your config file:</p>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[pytest]</span>
<span class="na">junit_suite_name</span> <span class="o">=</span> <span class="s">my_suite</span>
</pre></div>
</div>
<div class="section" id="record-xml-property">
<h3>record_xml_property<a class="headerlink" href="#record-xml-property" title="Permalink to this headline"></a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.8.</span></p>
</div>
<p>If you want to log additional information for a test, you can use the
<code class="docutils literal"><span class="pre">record_xml_property</span></code> fixture:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">test_function</span><span class="p">(</span><span class="n">record_xml_property</span><span class="p">):</span>
    <span class="n">record_xml_property</span><span class="p">(</span><span class="s2">&quot;example_key&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">assert</span> <span class="mi">0</span>
</pre></div>
</div>
<p>This will add an extra property <code class="docutils literal"><span class="pre">example_key=&quot;1&quot;</span></code> to the generated
<code class="docutils literal"><span class="pre">testcase</span></code> tag:</p>
<div class="highlight-xml"><div class="highlight"><pre><span></span><span class="nt">&lt;testcase</span> <span class="na">classname=</span><span class="s">&quot;test_function&quot;</span> <span class="na">file=</span><span class="s">&quot;test_function.py&quot;</span> <span class="na">line=</span><span class="s">&quot;0&quot;</span> <span class="na">name=</span><span class="s">&quot;test_function&quot;</span> <span class="na">time=</span><span class="s">&quot;0.0009&quot;</span><span class="nt">&gt;</span>
  <span class="nt">&lt;properties&gt;</span>
    <span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;example_key&quot;</span> <span class="na">value=</span><span class="s">&quot;1&quot;</span> <span class="nt">/&gt;</span>
  <span class="nt">&lt;/properties&gt;</span>
<span class="nt">&lt;/testcase&gt;</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p><code class="docutils literal"><span class="pre">record_xml_property</span></code> is an experimental feature, and its interface might be replaced
by something more powerful and general in future versions. The
functionality per-se will be kept, however.</p>
<p>Currently it does not work when used with the <code class="docutils literal"><span class="pre">pytest-xdist</span></code> plugin.</p>
<p class="last">Also please note that using this feature will break any schema verification.
This might be a problem when used with some CI servers.</p>
</div>
</div>
<div class="section" id="logxml-add-global-property">
<h3>LogXML: add_global_property<a class="headerlink" href="#logxml-add-global-property" title="Permalink to this headline"></a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.0.</span></p>
</div>
<p>If you want to add a properties node in the testsuite level, which may contains properties that are relevant
to all testcases you can use <code class="docutils literal"><span class="pre">LogXML.add_global_properties</span></code></p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pytest</span>

<span class="nd">@pytest.fixture</span><span class="p">(</span><span class="n">scope</span><span class="o">=</span><span class="s2">&quot;session&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">log_global_env_facts</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>

    <span class="k">if</span> <span class="n">pytest</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">pluginmanager</span><span class="o">.</span><span class="n">hasplugin</span><span class="p">(</span><span class="s1">&#39;junitxml&#39;</span><span class="p">):</span>
        <span class="n">my_junit</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">pytest</span><span class="o">.</span><span class="n">config</span><span class="p">,</span> <span class="s1">&#39;_xml&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>

    <span class="n">my_junit</span><span class="o">.</span><span class="n">add_global_property</span><span class="p">(</span><span class="s1">&#39;ARCH&#39;</span><span class="p">,</span> <span class="s1">&#39;PPC&#39;</span><span class="p">)</span>
    <span class="n">my_junit</span><span class="o">.</span><span class="n">add_global_property</span><span class="p">(</span><span class="s1">&#39;STORAGE_TYPE&#39;</span><span class="p">,</span> <span class="s1">&#39;CEPH&#39;</span><span class="p">)</span>

<span class="nd">@pytest.mark.usefixtures</span><span class="p">(</span><span class="n">log_global_env_facts</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">start_and_prepare_env</span><span class="p">():</span>
    <span class="k">pass</span>

<span class="k">class</span> <span class="nc">TestMe</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">test_foo</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">assert</span> <span class="bp">True</span>
</pre></div>
</div>
<p>This will add a property node below the testsuite node to the generated xml:</p>
<div class="highlight-xml"><div class="highlight"><pre><span></span><span class="nt">&lt;testsuite</span> <span class="na">errors=</span><span class="s">&quot;0&quot;</span> <span class="na">failures=</span><span class="s">&quot;0&quot;</span> <span class="na">name=</span><span class="s">&quot;pytest&quot;</span> <span class="na">skips=</span><span class="s">&quot;0&quot;</span> <span class="na">tests=</span><span class="s">&quot;1&quot;</span> <span class="na">time=</span><span class="s">&quot;0.006&quot;</span><span class="nt">&gt;</span>
  <span class="nt">&lt;properties&gt;</span>
    <span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;ARCH&quot;</span> <span class="na">value=</span><span class="s">&quot;PPC&quot;</span><span class="nt">/&gt;</span>
    <span class="nt">&lt;property</span> <span class="na">name=</span><span class="s">&quot;STORAGE_TYPE&quot;</span> <span class="na">value=</span><span class="s">&quot;CEPH&quot;</span><span class="nt">/&gt;</span>
  <span class="nt">&lt;/properties&gt;</span>
  <span class="nt">&lt;testcase</span> <span class="na">classname=</span><span class="s">&quot;test_me.TestMe&quot;</span> <span class="na">file=</span><span class="s">&quot;test_me.py&quot;</span> <span class="na">line=</span><span class="s">&quot;16&quot;</span> <span class="na">name=</span><span class="s">&quot;test_foo&quot;</span> <span class="na">time=</span><span class="s">&quot;0.000243663787842&quot;</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/testsuite&gt;</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">This is an experimental feature, and its interface might be replaced
by something more powerful and general in future versions. The
functionality per-se will be kept.</p>
</div>
</div>
</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>
<div class="deprecated">
<p><span class="versionmodified">Deprecated since version 3.0: </span>This option is rarely used and is scheduled for removal in 4.0.</p>
<p>An alternative for users which still need similar functionality is to use the
<a class="reference external" href="https://pypi.python.org/pypi/pytest-tap">pytest-tap</a> plugin which provides
a stream of test data.</p>
<p>If you have any concerns, please don't hesitate to
<a class="reference external" href="https://github.com/pytest-dev/pytest/issues">open an issue</a>.</p>
</div>
<p>To create plain-text machine-readable result files you can issue:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</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 <code class="docutils literal"><span class="pre">path</span></code> 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-default"><div class="highlight"><pre><span></span><span class="n">pytest</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 <code class="docutils literal"><span class="pre">-x</span></code> 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-default"><div class="highlight"><pre><span></span><span class="n">pytest</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="disabling-plugins">
<h2>Disabling plugins<a class="headerlink" href="#disabling-plugins" title="Permalink to this headline"></a></h2>
<p>To disable loading specific plugins at invocation time, use the <code class="docutils literal"><span class="pre">-p</span></code> option
together with the prefix <code class="docutils literal"><span class="pre">no:</span></code>.</p>
<p>Example: to disable loading the plugin <code class="docutils literal"><span class="pre">doctest</span></code>, which is responsible for
executing doctest tests from text files, invoke pytest like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span> <span class="o">-</span><span class="n">p</span> <span class="n">no</span><span class="p">:</span><span class="n">doctest</span>
</pre></div>
</div>
</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 class="versionmodified">New in version 2.0.</span></p>
</div>
<p>You can invoke <code class="docutils literal"><span class="pre">pytest</span></code> from Python code directly:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><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 &quot;pytest&quot; from the command line.
It will not raise <code class="docutils literal"><span class="pre">SystemExit</span></code> but return the exitcode instead.
You can pass in options and arguments:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pytest</span><span class="o">.</span><span class="n">main</span><span class="p">([</span><span class="s1">&#39;-x&#39;</span><span class="p">,</span> <span class="s1">&#39;mytestdir&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>You can specify additional plugins to <code class="docutils literal"><span class="pre">pytest.main</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># 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="nb">object</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="nb">print</span><span class="p">(</span><span class="s2">&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="s2">&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 <code class="docutils literal"><span class="pre">MyPlugin</span></code> was added and its
hook was invoked:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ python myinvoke.py
*** test run reporting finishing
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="contents.html">
              <img class="logo" src="_static/pytest1.png" alt="Logo"/>
            </a></p><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>
  <li><a href="backwards-compatibility.html">Backwards Compatibility</a></li>
  <li><a href="license.html">License</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 <code class="docutils literal"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">pytest</span></code></a></li>
<li><a class="reference internal" href="#possible-exit-codes">Possible exit codes</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-breakpoints">Setting breakpoints</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><ul>
<li><a class="reference internal" href="#record-xml-property">record_xml_property</a></li>
<li><a class="reference internal" href="#logxml-add-global-property">LogXML: add_global_property</a></li>
</ul>
</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="#disabling-plugins">Disabling plugins</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>Previous: <a href="getting-started.html" title="previous chapter">Installation and Getting Started</a></li>
      <li>Next: <a href="existingtestsuite.html" title="next chapter">Using pytest with an existing test suite</a></li>
  </ul></li>
</ul><h3>Useful Links</h3>
<ul>
  <li><a href="index.html">The pytest Website</a></li>
  <li><a href="contributing.html">Contribution Guide</a></li>
  <li><a href="https://pypi.python.org/pypi/pytest">pytest @ PyPI</a></li>
  <li><a href="https://github.com/pytest-dev/pytest/">pytest @ GitHub</a></li>
  <li><a href="http://plugincompat.herokuapp.com/">3rd party plugins</a></li>
  <li><a href="https://github.com/pytest-dev/pytest/issues">Issue Tracker</a></li>
  <li><a href="https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf">PDF Documentation</a>
</ul>

<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>

  <div class="footer">
    &copy; Copyright 2018, holger krekel and pytest-dev team.
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  

  </body>
</html>