172 lines
7.9 KiB
HTML
172 lines
7.9 KiB
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>1.4. Writing plugins — py lib v1.0.0b1 documentation</title>
|
|
<link rel="stylesheet" href="_static/default.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '',
|
|
VERSION: '1.0.0b1',
|
|
COLLAPSE_MODINDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
|
<link rel="top" title="py lib v1.0.0b1 documentation" href="index.html" />
|
|
<link rel="up" title="1. py.test" href="test.html" />
|
|
<link rel="next" title="1.5. Speed up test runs by sending tests to multiple CPUs" href="test-dist.html" />
|
|
<link rel="prev" title="1.3. Included plugins" href="test-plugins.html" />
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="genindex.html" title="General Index"
|
|
accesskey="I">index</a></li>
|
|
<li class="right" >
|
|
<a href="test-dist.html" title="1.5. Speed up test runs by sending tests to multiple CPUs"
|
|
accesskey="N">next</a> |</li>
|
|
<li class="right" >
|
|
<a href="test-plugins.html" title="1.3. Included plugins"
|
|
accesskey="P">previous</a> |</li>
|
|
<li><a href="index.html">py lib v1.0.0b1 documentation</a> »</li>
|
|
<li><a href="contents.html" >Contents</a> »</li>
|
|
<li><a href="test.html" accesskey="U">1. py.test</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<div class="section" id="writing-plugins">
|
|
<h1>1.4. Writing plugins<a class="headerlink" href="#writing-plugins" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="learning-by-examples">
|
|
<h2>1.4.1. Learning by examples<a class="headerlink" href="#learning-by-examples" title="Permalink to this headline">¶</a></h2>
|
|
<p>XXX</p>
|
|
<div class="section" id="adding-custom-options">
|
|
<h3>1.4.1.1. adding custom options<a class="headerlink" href="#adding-custom-options" title="Permalink to this headline">¶</a></h3>
|
|
<p>py.test supports adding of standard <a class="reference external" href="http://docs.python.org/library/optparse.html">optparse</a> Options.
|
|
A plugin may implement the <tt class="docutils literal"><span class="pre">addoption</span></tt> hook for registering
|
|
custom options:</p>
|
|
<div class="highlight-python"><pre>class ConftestPlugin:
|
|
def pytest_addoption(self, parser):
|
|
parser.addoption("-M", "--myopt", action="store",
|
|
help="specify string to set myopt")
|
|
|
|
def pytest_configure(self, config):
|
|
if config.option.myopt:
|
|
# do action based on option value</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="setting-default-values-for-test-options">
|
|
<h2>1.4.2. Setting default values for test options<a class="headerlink" href="#setting-default-values-for-test-options" title="Permalink to this headline">¶</a></h2>
|
|
<p>You can see all available command line options by running:</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">h</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>py.test will lookup values of options in this order:</p>
|
|
<ul class="simple">
|
|
<li>option value supplied at command line</li>
|
|
<li>content of environment variable <tt class="docutils literal"><span class="pre">PYTEST_OPTION_NAME=...</span></tt></li>
|
|
<li><tt class="docutils literal"><span class="pre">name</span> <span class="pre">=</span> <span class="pre">...</span></tt> setting in the nearest <tt class="docutils literal"><span class="pre">conftest.py</span></tt> file.</li>
|
|
</ul>
|
|
<p>The name of an option usually is the one you find
|
|
in the longform of the option, i.e. the name
|
|
behind the <tt class="docutils literal"><span class="pre">--</span></tt> double-dash.</p>
|
|
<p>IOW, you can set default values for options per project, per
|
|
home-directoray, per shell session or per test-run.</p>
|
|
</div>
|
|
<div class="section" id="plugin-methods">
|
|
<h2>1.4.3. Plugin methods<a class="headerlink" href="#plugin-methods" title="Permalink to this headline">¶</a></h2>
|
|
<p>A Plugin class may implement the following attributes and methods:</p>
|
|
<p>XXX</p>
|
|
<p><span class="target" id="pytest-event">pytest event</span>:</p>
|
|
</div>
|
|
<div class="section" id="pytest-events">
|
|
<h2>1.4.4. Pytest Events<a class="headerlink" href="#pytest-events" title="Permalink to this headline">¶</a></h2>
|
|
<p>XXX</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<h3><a href="index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference external" href="">1.4. Writing plugins</a><ul>
|
|
<li><a class="reference external" href="#learning-by-examples">1.4.1. Learning by examples</a><ul>
|
|
<li><a class="reference external" href="#adding-custom-options">1.4.1.1. adding custom options</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference external" href="#setting-default-values-for-test-options">1.4.2. Setting default values for test options</a></li>
|
|
<li><a class="reference external" href="#plugin-methods">1.4.3. Plugin methods</a></li>
|
|
<li><a class="reference external" href="#pytest-events">1.4.4. Pytest Events</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<h4>Previous topic</h4>
|
|
<p class="topless"><a href="test-plugins.html"
|
|
title="previous chapter">1.3. Included plugins</a></p>
|
|
<h4>Next topic</h4>
|
|
<p class="topless"><a href="test-dist.html"
|
|
title="next chapter">1.5. Speed up test runs by sending tests to multiple CPUs</a></p>
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="_sources/test-ext.txt"
|
|
rel="nofollow">Show Source</a></li>
|
|
</ul>
|
|
<div id="searchbox" style="display: none">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="search.html" method="get">
|
|
<input type="text" name="q" size="18" />
|
|
<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="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="genindex.html" title="General Index"
|
|
>index</a></li>
|
|
<li class="right" >
|
|
<a href="test-dist.html" title="1.5. Speed up test runs by sending tests to multiple CPUs"
|
|
>next</a> |</li>
|
|
<li class="right" >
|
|
<a href="test-plugins.html" title="1.3. Included plugins"
|
|
>previous</a> |</li>
|
|
<li><a href="index.html">py lib v1.0.0b1 documentation</a> »</li>
|
|
<li><a href="contents.html" >Contents</a> »</li>
|
|
<li><a href="test.html" >1. py.test</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2009, Holger Krekel.
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.7.
|
|
</div>
|
|
</body>
|
|
</html> |