Current File : //usr/share/doc/pytest-2.7.0/html/en/example/index.html
<!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>Usages and Examples</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.7.0',
        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="next" title="Demo of Python failure reports with pytest" href="reportingdemo.html" />
    <link rel="prev" title="List of Third-Party Plugins" href="../plugins_index/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="reportingdemo.html" title="Demo of Python failure reports with pytest"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="../plugins_index/index.html" title="List of Third-Party Plugins"
             accesskey="P">previous</a> |</li>
        <li><a href="../contents.html">pytest-2.7.0</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="usages-and-examples">
<span id="examples"></span><h1>Usages and Examples<a class="headerlink" href="#usages-and-examples" title="Permalink to this headline">¶</a></h1>
<p>Here is a (growing) list of examples. <a class="reference internal" href="../contact.html#contact"><em>Contact</em></a> us if you
need more examples or have questions. Also take a look at the
<a class="reference internal" href="../contents.html#toc"><em>comprehensive documentation</em></a> which contains many example
snippets as well.  Also, <a class="reference external" href="http://stackoverflow.com/search?q=pytest">pytest on stackoverflow.com</a> often comes with example
answers.</p>
<p>For basic examples, see</p>
<ul class="simple">
<li><a class="reference internal" href="../getting-started.html"><em>Installation and Getting Started</em></a> for basic introductory examples</li>
<li><a class="reference internal" href="../assert.html#assert"><em>Asserting with the assert statement</em></a> for basic assertion examples</li>
<li><a class="reference internal" href="../fixture.html#fixtures"><em>pytest fixtures: explicit, modular, scalable</em></a> for basic fixture/setup examples</li>
<li><a class="reference internal" href="../parametrize.html#parametrize"><em>Parametrizing fixtures and test functions</em></a> for basic test function parametrization</li>
<li><a class="reference internal" href="../unittest.html"><em>Support for unittest.TestCase / Integration of fixtures</em></a> for basic unittest integration</li>
<li><a class="reference internal" href="../nose.html"><em>Running tests written for nose</em></a> for basic nosetests integration</li>
</ul>
<p>The following examples aim at various use cases you might encounter.</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="reportingdemo.html">Demo of Python failure reports with pytest</a></li>
<li class="toctree-l1"><a class="reference internal" href="simple.html">Basic patterns and examples</a><ul>
<li class="toctree-l2"><a class="reference internal" href="simple.html#pass-different-values-to-a-test-function-depending-on-command-line-options">Pass different values to a test function, depending on command line options</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#dynamically-adding-command-line-options">Dynamically adding command line options</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#control-skipping-of-tests-according-to-command-line-option">Control skipping of tests according to command line option</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#writing-well-integrated-assertion-helpers">Writing well integrated assertion helpers</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#detect-if-running-from-within-a-pytest-run">Detect if running from within a pytest run</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#adding-info-to-test-report-header">Adding info to test report header</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#profiling-test-duration">profiling test duration</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#incremental-testing-test-steps">incremental testing - test steps</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#package-directory-level-fixtures-setups">Package/Directory-level fixtures (setups)</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#post-process-test-reports-failures">post-process test reports / failures</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#making-test-result-information-available-in-fixtures">Making test result information available in fixtures</a></li>
<li class="toctree-l2"><a class="reference internal" href="simple.html#integrating-pytest-runner-and-cx-freeze">Integrating pytest runner and cx_freeze</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="parametrize.html">Parametrizing tests</a><ul>
<li class="toctree-l2"><a class="reference internal" href="parametrize.html#generating-parameters-combinations-depending-on-command-line">Generating parameters combinations, depending on command line</a></li>
<li class="toctree-l2"><a class="reference internal" href="parametrize.html#different-options-for-test-ids">Different options for test IDs</a></li>
<li class="toctree-l2"><a class="reference internal" href="parametrize.html#a-quick-port-of-testscenarios">A quick port of &#8220;testscenarios&#8221;</a></li>
<li class="toctree-l2"><a class="reference internal" href="parametrize.html#deferring-the-setup-of-parametrized-resources">Deferring the setup of parametrized resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="parametrize.html#parametrizing-test-methods-through-per-class-configuration">Parametrizing test methods through per-class configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="parametrize.html#indirect-parametrization-with-multiple-fixtures">Indirect parametrization with multiple fixtures</a></li>
<li class="toctree-l2"><a class="reference internal" href="parametrize.html#indirect-parametrization-of-optional-implementations-imports">Indirect parametrization of optional implementations/imports</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="markers.html">Working with custom markers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="markers.html#marking-test-functions-and-selecting-them-for-a-run">Marking test functions and selecting them for a run</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#selecing-tests-based-on-their-node-id">Selecing tests based on their node ID</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#using-k-expr-to-select-tests-based-on-their-name">Using <tt class="docutils literal"><span class="pre">-k</span> <span class="pre">expr</span></tt> to select tests based on their name</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#registering-markers">Registering markers</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#marking-whole-classes-or-modules">Marking whole classes or modules</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#marking-individual-tests-when-using-parametrize">Marking individual tests when using parametrize</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#custom-marker-and-command-line-option-to-control-test-runs">Custom marker and command line option to control test runs</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#reading-markers-which-were-set-from-multiple-places">Reading markers which were set from multiple places</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#marking-platform-specific-tests-with-pytest">marking platform specific tests with pytest</a></li>
<li class="toctree-l2"><a class="reference internal" href="markers.html#automatically-adding-markers-based-on-test-names">Automatically adding markers based on test names</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="special.html">A session-fixture which can look at all collected tests</a></li>
<li class="toctree-l1"><a class="reference internal" href="pythoncollection.html">Changing standard (Python) test discovery</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pythoncollection.html#changing-directory-recursion">Changing directory recursion</a></li>
<li class="toctree-l2"><a class="reference internal" href="pythoncollection.html#changing-naming-conventions">Changing naming conventions</a></li>
<li class="toctree-l2"><a class="reference internal" href="pythoncollection.html#interpreting-cmdline-arguments-as-python-packages">Interpreting cmdline arguments as Python packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="pythoncollection.html#finding-out-what-is-collected">Finding out what is collected</a></li>
<li class="toctree-l2"><a class="reference internal" href="pythoncollection.html#customizing-test-collection-to-find-all-py-files">customizing test collection to find all .py files</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="nonpython.html">Working with non-python tests</a><ul>
<li class="toctree-l2"><a class="reference internal" href="nonpython.html#a-basic-example-for-specifying-tests-in-yaml-files">A basic example for specifying tests in Yaml files</a></li>
</ul>
</li>
</ul>
</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="../getting-started.html">Install</a></li>
  <li><a href="#">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><h3>Related Topics</h3>
<ul>
  <li><a href="../contents.html">Documentation overview</a><ul>
      <li>Previous: <a href="../plugins_index/index.html" title="previous chapter">List of Third-Party Plugins</a></li>
      <li>Next: <a href="reportingdemo.html" title="next chapter">Demo of Python failure reports with pytest</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://bitbucket.org/pytest-dev/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/pytest-dev/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>
  
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-7597274-13']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

  </body>
</html>