This file is indexed.

/usr/share/doc/python-pytest-doc/html/getting-started.html is in python-pytest-doc 2.6.3-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
<!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/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.6.2',
        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="shortcut icon" href="_static/pytest1favi.ico"/>
    <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="pytest: helps you write better programs" href="index.html" />
   
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">

  </head>
  <body>
  
  

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="usage.html" title="Usage and Invocations"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="index.html" title="pytest: helps you write better programs"
             accesskey="P">previous</a> |</li>
        <li><a href="contents.html">pytest-2.6.2</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="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.6-3.4, Jython, PyPy-2.3</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>dependencies</strong>: <a class="reference external" href="http://pypi.python.org/pypi/py">py</a>,
<a class="reference external" href="http://pypi.python.org/pypi/colorama">colorama (Windows)</a>,
<a class="reference external" href="http://pypi.python.org/pypi/argparse">argparse (py26)</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><span id="id1"></span><h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h2>
<p>Installation options:</p>
<div class="highlight-python"><div class="highlight"><pre>pip install -U pytest # or
easy_install -U pytest
</pre></div>
</div>
<p>To check your installation has installed the correct version:</p>
<div class="highlight-python"><div class="highlight"><pre>$ py.test --version
This is pytest version 2.6.3, imported from /home/hpk/p/pytest/.tox/regen/lib/python3.4/site-packages/pytest.py
</pre></div>
</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"><div class="highlight"><pre>$ py.test
=========================== test session starts ============================
platform linux -- Python 3.4.0 -- py-1.4.25 -- pytest-2.6.3
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.01 seconds =========================
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">pytest</span></tt> 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"><div class="highlight"><pre>$ py.test -q test_sysexit.py
.
1 passed in 0.00 seconds
</pre></div>
</div>
<div class="admonition-todo admonition" id="index-0">
<p class="first admonition-title">Todo</p>
<p class="last">For further ways to assert exceptions see the <cite>raises</cite></p>
</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>Conventions for Python test discovery</em></a>.
There is no need to subclass anything.  We can simply
run the module by passing its filename:</p>
<div class="highlight-python"><div class="highlight"><pre>$ py.test -q test_class.py
.F
================================= FAILURES =================================
____________________________ TestClass.test_two ____________________________

self = &lt;test_class.TestClass object at 0x2b39478f7438&gt;

    def test_two(self):
        x = &quot;hello&quot;
&gt;       assert hasattr(x, &#39;check&#39;)
E       assert hasattr(&#39;hello&#39;, &#39;check&#39;)

test_class.py:8: AssertionError
1 failed, 1 passed in 0.01 seconds
</pre></div>
</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.  pytest provides
<a class="reference internal" href="builtin.html#builtinfixtures"><em>Builtin fixtures/function arguments</em></a> which allow 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="p">(</span><span class="n">tmpdir</span><span class="p">)</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
<tt class="docutils literal"><span class="pre">pytest</span></tt> will lookup and call a fixture factory to create the resource
before performing the test function call.  Let&#8217;s just run it:</p>
<div class="highlight-python"><div class="highlight"><pre>$ py.test -q test_tmpdir.py
F
================================= FAILURES =================================
_____________________________ test_needsfiles ______________________________

tmpdir = local(&#39;/tmp/pytest-18/test_needsfiles0&#39;)

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

test_tmpdir.py:3: AssertionError
--------------------------- Captured stdout call ---------------------------
/tmp/pytest-18/test_needsfiles0
1 failed in 0.01 seconds
</pre></div>
</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="fixture.html#fixtures"><em>pytest fixtures: explicit, modular, scalable</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">fixtures</span>   <span class="c"># shows builtin and custom fixtures</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="fixture.html#fixtures"><em>pytest fixtures: explicit, modular, scalable</em></a> for providing a functional baseline to your tests</li>
<li><a class="reference internal" href="apiref.html#apiref"><em>pytest reference documentation</em></a> for documentation and examples on using <tt class="docutils literal"><span class="pre">pytest</span></tt></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>Install <a class="reference external" href="http://pypi.python.org/pypi/setuptools">setuptools</a> to get <tt class="docutils literal"><span class="pre">easy_install</span></tt> which allows to install
<tt class="docutils literal"><span class="pre">.egg</span></tt> binary format packages in addition to source-based ones.</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 your tests with Jython using <tt class="docutils literal"><span class="pre">pytest</span></tt>.</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="sphinxsidebar">
        <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="#">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="#">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>
<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="index.html" title="previous chapter">pytest: helps you write better programs</a></li>
      <li>Next: <a href="usage.html" title="next chapter">Usage and Invocations</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="contributing.html">Contribution Guide</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="http://pytest.org/latest/plugins_index/index.html">3rd party plugins</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 2014, holger krekel.
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  

  </body>
</html>