~crunch.io/ubuntu/precise/codespeak-lib/unstable

« back to all changes in this revision

Viewing changes to doc/test/xunit_setup.html

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-08-01 16:24:01 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100801162401-g37v49d1p148alpm
Tags: 1.3.3-1
* New upstream release.
* Bump Standards-Version to 3.9.1.
* Fix typo in py.test manpage.
* Prefer Breaks: over Conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
 
<html>
3
 
  <head>
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>
7
 
  <body>
8
 
    <div id="navspace">
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>
10
 
      <div id="menubar">
11
 
        <div>
12
 
          <div><a class="menu" href="../announce/release-1.2.1.html">1.2.1 ANN</a></div></div>
13
 
        <div>
14
 
          <div><a class="menu" href="../install.html">INSTALL</a></div></div>
15
 
        <div>
16
 
          <div><a class="menu" href="../contact.html">CONTACT</a></div></div>
17
 
        <div>
18
 
          <div><a class="menu" href="../changelog.html">CHANGELOG</a></div></div>
19
 
        <div>
20
 
          <div><a class="menu" href="../faq.html">FAQ</a></div></div>
21
 
        <div>
22
 
          <div>
23
 
            <h3>py.test:</h3>
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>
31
 
        <div>
32
 
          <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>
40
 
 
41
 
<p>Note:</p>
42
 
<blockquote>
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
48
 
patter.</blockquote>
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">&quot;&quot;&quot; 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">    &quot;&quot;&quot;</span>
66
 
 
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">&quot;&quot;&quot; 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">    &quot;&quot;&quot;</span>
71
 
</pre></div>
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">&quot;&quot;&quot; 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">    &quot;&quot;&quot;</span>
77
 
 
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">&quot;&quot;&quot; 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">    &quot;&quot;&quot;</span>
82
 
 
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">&quot;&quot;&quot; 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">    &quot;&quot;&quot;</span>
88
 
 
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">&quot;&quot;&quot; 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">    &quot;&quot;&quot;</span>
93
 
</pre></div>
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>
99
 
</div>
100
 
</div>
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"));
104
 
</script>
105
 
<script type="text/javascript">
106
 
try {
107
 
var pageTracker = _gat._getTracker("UA-7597274-3");
108
 
pageTracker._trackPageview();
109
 
} catch(err) {}</script>
110
 
</body></html>
 
 
b'\\ No newline at end of file'