This file is indexed.

/usr/share/doc/python-pytest-doc/html/getting-started.html is in python-pytest-doc 2.2.4-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
<!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>Installation and Getting Started</title>
    
    <link rel="stylesheet" href="_static/sphinxdoc.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.2.4',
        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="Usage and Invocations" href="usage.html" />
    <link rel="prev" title="Welcome to pytest!" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a></li>
        <li class="right" >
          <a href="usage.html" title="Usage and Invocations"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Welcome to pytest!"
             accesskey="P">previous</a> |</li>
        <li><a href="contents.html">pytest-2.2.4</a> &raquo;</li>
          <li><a href="overview.html" accesskey="U">Getting started basics</a> &raquo;</li>
 

      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Search" />
      <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>

<h3>quicklinks</h3>
<div style="text-align: left; font-size: 100%; vertical-align: middle;">
<table>
<tr>
<td>
        <a href="index.html">home</a>
</td><td>
        <a href="contents.html">TOC/contents</a>
</td></tr><tr><td>
        <a href="#">install</a>
</td><td>
        <a href="changelog.html">changelog</a>
</td></tr><tr><td>
        <a href="example/index.html">examples</a>
</td><td>
        <a href="customize.html">customize</a>
</td></tr><tr><td>
        <a href="https://bitbucket.org/hpk42/pytest/issues?status=new&status=open">issues[bb]</a>
</td><td>
        <a href="contact.html">contact</a>
</td></tr></table>
</div>

  <h3><a href="contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Installation and Getting Started</a><ul>
<li><a class="reference internal" href="#installation">Installation</a></li>
<li><a class="reference internal" href="#our-first-test-run">Our first test run</a></li>
<li><a class="reference internal" href="#asserting-that-a-certain-exception-is-raised">Asserting that a certain exception is raised</a></li>
<li><a class="reference internal" href="#grouping-multiple-tests-in-a-class">Grouping multiple tests in a class</a></li>
<li><a class="reference internal" href="#going-functional-requesting-a-unique-temporary-directory">Going functional: requesting a unique temporary directory</a></li>
<li><a class="reference internal" href="#where-to-go-next">Where to go next</a></li>
<li><a class="reference internal" href="#known-installation-issues">Known Installation issues</a><ul>
<li><a class="reference internal" href="#easy-install-or-pip-not-found">easy_install or pip not found?</a></li>
<li><a class="reference internal" href="#py-test-not-found-on-windows-despite-installation">py.test not found on Windows despite installation?</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Welcome to pytest!</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="usage.html"
                        title="next chapter">Usage and Invocations</a></p>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="installation-and-getting-started">
<h1>Installation and Getting Started<a class="headerlink" href="#installation-and-getting-started" title="Permalink to this headline"></a></h1>
<p><strong>Pythons</strong>: Python 2.4-3.2, Jython, PyPy</p>
<p><strong>Platforms</strong>: Unix/Posix and Windows</p>
<p><strong>PyPI package name</strong>: <a class="reference external" href="http://pypi.python.org/pypi/pytest">pytest</a></p>
<p><strong>documentation as PDF</strong>: <a class="reference external" href="http://pytest.org/latest/pytest.pdf">download latest</a></p>
<div class="section" id="installation">
<span id="getstarted"></span><h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h2>
<p>Installation options:</p>
<div class="highlight-python"><pre>pip install -U pytest # or
easy_install -U pytest</pre>
</div>
<p>To check your installation has installed the correct version:</p>
<div class="highlight-python"><pre>$ py.test --version
This is py.test version 2.2.2, imported from /Users/hpk/p/pytest/pytest.pyc
setuptools registered plugins:
  pytest-xdist-1.8 at /Users/hpk/p/pytest-xdist/xdist/plugin.pyc
  pytest-cov-1.4 at /Users/hpk/venv/0/lib/python2.7/site-packages/pytest_cov.pyc</pre>
</div>
<p>If you get an error checkout <a class="reference internal" href="#installation-issues"><em>Known Installation issues</em></a>.</p>
</div>
<div class="section" id="our-first-test-run">
<span id="simpletest"></span><h2>Our first test run<a class="headerlink" href="#our-first-test-run" title="Permalink to this headline"></a></h2>
<p>Let&#8217;s create a first test file with a simple test function:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># content of test_sample.py</span>
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span>

<span class="k">def</span> <span class="nf">test_answer</span><span class="p">():</span>
    <span class="k">assert</span> <span class="n">func</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">5</span>
</pre></div>
</div>
<p>That&#8217;s it. You can execute the test function now:</p>
<div class="highlight-python"><pre>$ py.test
=========================== test session starts ============================
platform darwin -- Python 2.7.1 -- pytest-2.2.2
collecting ... collected 1 items

test_sample.py F

================================= FAILURES =================================
_______________________________ test_answer ________________________________

    def test_answer():
&gt;       assert func(3) == 5
E       assert 4 == 5
E        +  where 4 = func(3)

test_sample.py:5: AssertionError
========================= 1 failed in 0.02 seconds =========================</pre>
</div>
<p>py.test found the <tt class="docutils literal"><span class="pre">test_answer</span></tt> function by following <a class="reference internal" href="goodpractises.html#test-discovery"><em>standard test discovery rules</em></a>, basically detecting the <tt class="docutils literal"><span class="pre">test_</span></tt> prefixes.  We got a failure report because our little <tt class="docutils literal"><span class="pre">func(3)</span></tt> call did not return <tt class="docutils literal"><span class="pre">5</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You can simply use the <tt class="docutils literal"><span class="pre">assert</span></tt> statement for asserting test
expectations.  pytest&#8217;s <a class="reference internal" href="assert.html#assert-introspection"><em>Advanced assertion introspection</em></a> will intelligently
report intermediate values of the assert expression freeing
you from the need to learn the many names of <a class="reference external" href="http://docs.python.org/library/unittest.html#test-cases">JUnit legacy methods</a>.</p>
</div>
</div>
<div class="section" id="asserting-that-a-certain-exception-is-raised">
<h2>Asserting that a certain exception is raised<a class="headerlink" href="#asserting-that-a-certain-exception-is-raised" title="Permalink to this headline"></a></h2>
<p>If you want to assert that some code raises an exception you can
use the <tt class="docutils literal"><span class="pre">raises</span></tt> helper:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># content of test_sysexit.py</span>
<span class="kn">import</span> <span class="nn">pytest</span>
<span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
    <span class="k">raise</span> <span class="ne">SystemExit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">test_mytest</span><span class="p">():</span>
    <span class="k">with</span> <span class="n">pytest</span><span class="o">.</span><span class="n">raises</span><span class="p">(</span><span class="ne">SystemExit</span><span class="p">):</span>
        <span class="n">f</span><span class="p">()</span>
</pre></div>
</div>
<p>Running it with, this time in &#8220;quiet&#8221; reporting mode:</p>
<div class="highlight-python"><pre>$ py.test -q test_sysexit.py
collecting ... collected 1 items
.
1 passed in 0.01 seconds</pre>
</div>
</div>
<div class="section" id="grouping-multiple-tests-in-a-class">
<h2>Grouping multiple tests in a class<a class="headerlink" href="#grouping-multiple-tests-in-a-class" title="Permalink to this headline"></a></h2>
<p>Once you start to have more than a few tests it often makes sense
to group tests logically, in classes and modules.  Let&#8217;s write a class
containing two tests:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># content of test_class.py</span>
<span class="k">class</span> <span class="nc">TestClass</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">test_one</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">x</span> <span class="o">=</span> <span class="s">&quot;this&quot;</span>
        <span class="k">assert</span> <span class="s">&#39;h&#39;</span> <span class="ow">in</span> <span class="n">x</span>

    <span class="k">def</span> <span class="nf">test_two</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">x</span> <span class="o">=</span> <span class="s">&quot;hello&quot;</span>
        <span class="k">assert</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="s">&#39;check&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The two tests are found because of the standard <a class="reference internal" href="goodpractises.html#test-discovery"><em>Integration with setuptools/distribute test commands</em></a>.
There is no need to subclass anything.  We can simply
run the module by passing its filename:</p>
<div class="highlight-python"><pre>$ py.test -q test_class.py
collecting ... collected 2 items
.F
================================= FAILURES =================================
____________________________ TestClass.test_two ____________________________

self = &lt;test_class.TestClass instance at 0x1013225a8&gt;

    def test_two(self):
        x = "hello"
&gt;       assert hasattr(x, 'check')
E       assert hasattr('hello', 'check')

test_class.py:8: AssertionError
1 failed, 1 passed in 0.03 seconds</pre>
</div>
<p>The first test passed, the second failed. Again we can easily see
the intermediate values used in the assertion, helping us to
understand the reason for the failure.</p>
</div>
<div class="section" id="going-functional-requesting-a-unique-temporary-directory">
<h2>Going functional: requesting a unique temporary directory<a class="headerlink" href="#going-functional-requesting-a-unique-temporary-directory" title="Permalink to this headline"></a></h2>
<p>For functional tests one often needs to create some files
and pass them to application objects.  py.test provides
the versatile <a class="reference internal" href="funcargs.html#funcarg-mechanism"><em>Dependency injection through function arguments</em></a> which allows to request
arbitrary resources, for example a unique temporary directory:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># content of test_tmpdir.py</span>
<span class="k">def</span> <span class="nf">test_needsfiles</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">):</span>
    <span class="k">print</span> <span class="n">tmpdir</span>
    <span class="k">assert</span> <span class="mi">0</span>
</pre></div>
</div>
<p>We list the name <tt class="docutils literal"><span class="pre">tmpdir</span></tt> in the test function signature and
py.test will lookup and call a factory to create the resource
before performing the test function call.  Let&#8217;s just run it:</p>
<div class="highlight-python"><pre>$ py.test -q test_tmpdir.py
collecting ... collected 1 items
F
================================= FAILURES =================================
_____________________________ test_needsfiles ______________________________

tmpdir = local('/Users/hpk/tmp/pytest-20/test_needsfiles0')

    def test_needsfiles(tmpdir):
        print tmpdir
&gt;       assert 0
E       assert 0

test_tmpdir.py:3: AssertionError
----------------------------- Captured stdout ------------------------------
/Users/hpk/tmp/pytest-20/test_needsfiles0
1 failed in 0.11 seconds</pre>
</div>
<p>Before the test runs, a unique-per-test-invocation temporary directory
was created.  More info at <a class="reference internal" href="tmpdir.html#tmpdir-handling"><em>Temporary directories and files</em></a>.</p>
<p>You can find out what kind of builtin <a class="reference internal" href="funcargs.html#funcargs"><em>Dependency injection through function arguments</em></a> exist by typing:</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">funcargs</span>   <span class="c"># shows builtin and custom function arguments</span>
</pre></div>
</div>
</div>
<div class="section" id="where-to-go-next">
<h2>Where to go next<a class="headerlink" href="#where-to-go-next" title="Permalink to this headline"></a></h2>
<p>Here are a few suggestions where to go next:</p>
<ul class="simple">
<li><a class="reference internal" href="usage.html#cmdline"><em>Calling pytest through python -m pytest</em></a> for command line invocation examples</li>
<li><a class="reference internal" href="goodpractises.html#goodpractises"><em>good practises</em></a> for virtualenv, test layout, genscript support</li>
<li><a class="reference internal" href="apiref.html#apiref"><em>py.test reference documentation</em></a> for documentation and examples on using py.test</li>
<li><a class="reference internal" href="plugins.html#plugins"><em>Working with plugins and conftest files</em></a> managing and writing plugins</li>
</ul>
</div>
<div class="section" id="known-installation-issues">
<span id="installation-issues"></span><h2>Known Installation issues<a class="headerlink" href="#known-installation-issues" title="Permalink to this headline"></a></h2>
<div class="section" id="easy-install-or-pip-not-found">
<h3>easy_install or pip not found?<a class="headerlink" href="#easy-install-or-pip-not-found" title="Permalink to this headline"></a></h3>
<p><a class="reference external" href="http://www.pip-installer.org/en/latest/index.html">Install pip</a> for a state of the art python package installer.</p>
<p>Or consult <a class="reference external" href="http://pypi.python.org/pypi/distribute">distribute docs</a> to install the <tt class="docutils literal"><span class="pre">easy_install</span></tt>
tool on your machine.</p>
<p>You may also use the older <a class="reference external" href="http://pypi.python.org/pypi/setuptools">setuptools</a> project but it lacks bug fixes
and does not work on Python3.</p>
</div>
<div class="section" id="py-test-not-found-on-windows-despite-installation">
<h3>py.test not found on Windows despite installation?<a class="headerlink" href="#py-test-not-found-on-windows-despite-installation" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><strong>Windows</strong>: If &#8220;easy_install&#8221; or &#8220;py.test&#8221; are not found
you need to add the Python script path to your <tt class="docutils literal"><span class="pre">PATH</span></tt>, see here:
<a class="reference external" href="http://www.imladris.com/Scripts/PythonForWindows.html">Python for Windows</a>.  You may alternatively use an <a class="reference external" href="http://www.activestate.com/activepython/downloads">ActivePython install</a>
which does this for you automatically.</li>
</ul>
<ul class="simple">
<li><strong>Jython2.5.1 on Windows XP</strong>: <a class="reference external" href="http://bugs.jython.org/issue1491">Jython does not create command line launchers</a>
so <tt class="docutils literal"><span class="pre">py.test</span></tt> will not work correctly.  You may install py.test on
CPython and type <tt class="docutils literal"><span class="pre">py.test</span> <span class="pre">--genscript=mytest</span></tt> and then use
<tt class="docutils literal"><span class="pre">jython</span> <span class="pre">mytest</span></tt> to run py.test for your tests to run with Jython.</li>
</ul>
<blockquote>
<div><a class="reference internal" href="example/index.html#examples"><em>Usages and Examples</em></a> for more complex examples</div></blockquote>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a></li>
        <li class="right" >
          <a href="usage.html" title="Usage and Invocations"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Welcome to pytest!"
             >previous</a> |</li>
        <li><a href="contents.html">pytest-2.2.4</a> &raquo;</li>
          <li><a href="overview.html" >Getting started basics</a> &raquo;</li>
 

      </ul>
    </div>

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

  </body>
</html>