1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<title>py.test xunit_setup</title>
5
<meta content="text/html;charset=ISO-8859-1" name="Content-Type"/>
6
<link href="../style.css" media="screen" rel="stylesheet" type="text/css"/></head>
9
<div><a href="http://pylib.org"><img alt="py lib" height="57" id="pyimg" src="http://codespeak.net/img/pylib.png" width="77"/></a></div>
12
<div><a class="menu" href="../announce/release-1.2.1.html">1.2.1 ANN</a></div></div>
14
<div><a class="menu" href="../install.html">INSTALL</a></div></div>
16
<div><a class="menu" href="../contact.html">CONTACT</a></div></div>
18
<div><a class="menu" href="../changelog.html">CHANGELOG</a></div></div>
20
<div><a class="menu" href="../faq.html">FAQ</a></div></div>
24
<div><a class="menu" href="index.html">Index</a></div>
25
<div><a class="menu" href="quickstart.html">Quickstart</a></div>
26
<div><a class="menu" href="features.html">Features</a></div>
27
<div><a class="menu" href="plugin/index.html">Plugins</a></div>
28
<div><a class="menu" href="funcargs.html">Funcargs</a></div>
29
<div><a class="menu" href="customize.html">Customize</a></div>
30
<div><a class="menu" href="talks.html">Tutorials</a></div></div></div>
33
<h3>supporting APIs:</h3>
34
<div><a class="menu" href="../index.html">Index</a></div>
35
<div><a class="menu" href="../path.html">py.path</a></div>
36
<div><a class="menu" href="../code.html">py.code</a></div></div></div></div></div>
37
<div id="contentspace">
38
<div class="document" id="extended-xunit-style-setup">
39
<h1 class="title">extended xUnit style setup</h1>
43
Since version 1.0 <a class="reference external" href="funcargs.html">funcargs</a> present the new and
44
more powerful way to manage test setups with larger
45
test suites. <em>funcargs</em> also provide flexible
46
<a class="reference external" href="funcargs.html#parametrizing-tests">test parametrization</a> which goes way beyond
47
what you can do with the xUnit setup/teardown-method
49
<p>Python, Java and many other languages have a tradition
50
of using <a class="reference external" href="http://en.wikipedia.org/wiki/XUnit">xUnit</a> style testing. This typically
51
involves the call of a <tt class="docutils literal">setup</tt> method before
52
a test function is run and <tt class="docutils literal">teardown</tt> after
53
it finishes. With <tt class="docutils literal">py.test</tt> there are three
54
scopes for which you can provide setup/teardown
55
hooks to provide test fixtures: per-module, per-class
56
and per-method/function. <tt class="docutils literal">py.test</tt> will
57
discover and call according methods automatically.</p>
58
<p>The <a class="reference external" href="plugin/unittest.html">unittest plugin</a> also will intregate <tt class="docutils literal">unittest.TestCase</tt>
59
instances into a test run and call respective setup/teardown methods.</p>
60
<p>All setup/teardown methods are optional.</p>
61
<p>The following methods are called at module level if they exist:</p>
62
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">setup_module</span>(module):
63
<span style="color: #BA2121; font-style: italic">""" setup up any state specific to the execution</span>
64
<span style="color: #BA2121; font-style: italic"> of the given module.</span>
65
<span style="color: #BA2121; font-style: italic"> """</span>
67
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">teardown_module</span>(module):
68
<span style="color: #BA2121; font-style: italic">""" teardown any state that was previously setup</span>
69
<span style="color: #BA2121; font-style: italic"> with a setup_module method.</span>
70
<span style="color: #BA2121; font-style: italic"> """</span>
72
<p>The following hooks are available for test classes:</p>
73
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">setup_class</span>(cls):
74
<span style="color: #BA2121; font-style: italic">""" setup up any state specific to the execution</span>
75
<span style="color: #BA2121; font-style: italic"> of the given class (which usually contains tests).</span>
76
<span style="color: #BA2121; font-style: italic"> """</span>
78
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">teardown_class</span>(cls):
79
<span style="color: #BA2121; font-style: italic">""" teardown any state that was previously setup</span>
80
<span style="color: #BA2121; font-style: italic"> with a call to setup_class.</span>
81
<span style="color: #BA2121; font-style: italic"> """</span>
83
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">setup_method</span>(<span style="color: #008000">self</span>, method):
84
<span style="color: #BA2121; font-style: italic">""" setup up any state tied to the execution of the given</span>
85
<span style="color: #BA2121; font-style: italic"> method in a class. setup_method is invoked for every</span>
86
<span style="color: #BA2121; font-style: italic"> test method of a class.</span>
87
<span style="color: #BA2121; font-style: italic"> """</span>
89
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">teardown_method</span>(<span style="color: #008000">self</span>, method):
90
<span style="color: #BA2121; font-style: italic">""" teardown any state that was previously setup</span>
91
<span style="color: #BA2121; font-style: italic"> with a setup_method call.</span>
92
<span style="color: #BA2121; font-style: italic"> """</span>
94
<p>The last two hooks, <tt class="docutils literal">setup_method</tt> and <tt class="docutils literal">teardown_method</tt>, are
95
equivalent to <tt class="docutils literal">setUp</tt> and <tt class="docutils literal">tearDown</tt> in the Python standard
96
library's <a class="reference external" href="http://docs.python.org/library/unittest.html">unittest.py module</a>.</p>
97
<p>Note that it possible that setup/teardown pairs are invoked multiple
98
times per testing process.</p>
101
<script type="text/javascript">
102
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
103
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
105
<script type="text/javascript">
107
var pageTracker = _gat._getTracker("UA-7597274-3");
108
pageTracker._trackPageview();
109
} catch(err) {}</script>
b'\\ No newline at end of file'