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

« back to all changes in this revision

Viewing changes to doc/test/plugin/xfail.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>xfail</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 style="font-style: italic;">trunk</div>
12
 
        <div>
13
 
          <div><a class="menu" href="../../download.html">install</a></div></div>
14
 
        <div>
15
 
          <div><a class="menu" href="../../contact.html">contact</a></div></div>
16
 
        <div>
17
 
          <div><a class="menu" href="../../changelog.html">changelog</a></div></div>
18
 
        <div>
19
 
          <div><a class="menu" href="../../faq.html">faq</a></div></div>
20
 
        <div>
21
 
          <div>
22
 
            <h3>py.test:</h3>
23
 
            <div><a class="menu" href="../index.html">doc index</a></div>
24
 
            <div><a class="menu" href="../features.html">features</a></div>
25
 
            <div><a class="menu" href="../quickstart.html">quickstart</a></div>
26
 
            <div><a class="menu" href="../talks.html">tutorials</a></div>
27
 
            <div><a class="menu" href="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></div></div>
30
 
        <div>
31
 
          <div>
32
 
            <h3>supporting APIs:</h3>
33
 
            <div><a class="menu" href="../../index.html">pylib index</a></div>
34
 
            <div><a class="menu" href="../../execnet.html">py.execnet</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
 
 
39
 
 
40
 
<div class="section" id="pytest-xfail-plugin">
41
 
<h1>pytest_xfail plugin</h1>
42
 
<p>mark python test functions, classes or modules for conditional</p>
43
 
<div class="contents local topic" id="contents">
44
 
<ul class="simple">
45
 
<li><a class="reference internal" href="#skip-a-test-function-conditionally" id="id1">skip a test function conditionally</a></li>
46
 
<li><a class="reference internal" href="#conditionally-mark-a-function-as-expected-to-fail" id="id2">conditionally mark a function as &quot;expected to fail&quot;</a></li>
47
 
<li><a class="reference internal" href="#skip-xfail-a-whole-test-class-or-module" id="id3">skip/xfail a whole test class or module</a></li>
48
 
<li><a class="reference internal" href="#skip-if-a-dependency-cannot-be-imported" id="id4">skip if a dependency cannot be imported</a></li>
49
 
<li><a class="reference internal" href="#dynamically-skip-from-within-a-test-or-setup" id="id5">dynamically skip from within a test or setup</a></li>
50
 
</ul>
51
 
</div>
52
 
<p>skipping (skipif) or as expected-to-fail (xfail).  Both declarations
53
 
lead to special reporting and both can be systematically associated
54
 
with functions, whole classes or modules. The difference between
55
 
the two is that 'xfail' will still execute test functions
56
 
but it will revert the outcome.  A passing test is now
57
 
a failure and failing test is expected.  All skip conditions
58
 
are reported at the end of test run through the terminal
59
 
reporter.</p>
60
 
<div class="section" id="skip-a-test-function-conditionally">
61
 
<span id="skipif"></span><h2><a class="toc-backref" href="#id1">skip a test function conditionally</a></h2>
62
 
<p>Here is an example for skipping a test function on Python3:</p>
63
 
<pre class="literal-block">
64
 
&#64;py.test.mark.skipif(&quot;sys.version_info &gt;= (3,0)&quot;)
65
 
def test_function():
66
 
    ...
67
 
</pre>
68
 
<p>Conditions are specified as python expressions
69
 
and can access the <tt class="docutils literal"><span class="pre">sys</span></tt> module.  They can also
70
 
access the config object and thus depend on command
71
 
line or conftest options:</p>
72
 
<pre class="literal-block">
73
 
&#64;py.test.mark.skipif(&quot;config.getvalue('db') is None&quot;)
74
 
def test_function(...):
75
 
    ...
76
 
</pre>
77
 
</div>
78
 
<div class="section" id="conditionally-mark-a-function-as-expected-to-fail">
79
 
<h2><a class="toc-backref" href="#id2">conditionally mark a function as &quot;expected to fail&quot;</a></h2>
80
 
<p>You can use the <tt class="docutils literal"><span class="pre">xfail</span></tt> keyword to mark your test functions as
81
 
'expected to fail':</p>
82
 
<pre class="literal-block">
83
 
&#64;py.test.mark.xfail
84
 
def test_hello():
85
 
    ...
86
 
</pre>
87
 
<p>This test will be executed but no traceback will be reported
88
 
when it fails. Instead terminal reporting will list it in the
89
 
&quot;expected to fail&quot; or &quot;unexpectedly passing&quot; sections.
90
 
As with <a class="reference internal" href="#skipif">skipif</a> you may selectively expect a failure
91
 
depending on platform:</p>
92
 
<pre class="literal-block">
93
 
&#64;py.test.mark.xfail(&quot;sys.version_info &gt;= (3,0)&quot;)
94
 
def test_function():
95
 
    ...
96
 
</pre>
97
 
</div>
98
 
<div class="section" id="skip-xfail-a-whole-test-class-or-module">
99
 
<h2><a class="toc-backref" href="#id3">skip/xfail a whole test class or module</a></h2>
100
 
<p>Instead of marking single functions you can skip
101
 
a whole class of tests when runnign on a specific
102
 
platform:</p>
103
 
<pre class="literal-block">
104
 
class TestSomething:
105
 
    skipif = &quot;sys.platform == 'win32'&quot;
106
 
</pre>
107
 
<p>Or you can mark all test functions as expected
108
 
to fail for a specific test configuration:</p>
109
 
<pre class="literal-block">
110
 
xfail = &quot;config.getvalue('db') == 'mysql'&quot;
111
 
</pre>
112
 
</div>
113
 
<div class="section" id="skip-if-a-dependency-cannot-be-imported">
114
 
<h2><a class="toc-backref" href="#id4">skip if a dependency cannot be imported</a></h2>
115
 
<p>You can use a helper to skip on a failing import:</p>
116
 
<pre class="literal-block">
117
 
docutils = py.test.importorskip(&quot;docutils&quot;)
118
 
</pre>
119
 
<p>You can use this helper at module level or within
120
 
a test or setup function.</p>
121
 
<p>You can aslo skip if a library does not have the right version:</p>
122
 
<pre class="literal-block">
123
 
docutils = py.test.importorskip(&quot;docutils&quot;, minversion=&quot;0.3&quot;)
124
 
</pre>
125
 
<p>The version will be read from the specified module's <tt class="docutils literal"><span class="pre">__version__</span></tt> attribute.</p>
126
 
</div>
127
 
<div class="section" id="dynamically-skip-from-within-a-test-or-setup">
128
 
<h2><a class="toc-backref" href="#id5">dynamically skip from within a test or setup</a></h2>
129
 
<p>If you want to skip the execution of a test you can call
130
 
<tt class="docutils literal"><span class="pre">py.test.skip()</span></tt> within a test, a setup or from a
131
 
<a class="reference external" href="../funcargs.html#factory">funcarg factory</a> function.  Example:</p>
132
 
<pre class="literal-block">
133
 
def test_function():
134
 
    if not valid_config():
135
 
        py.test.skip(&quot;unsuppored configuration&quot;)
136
 
</pre>
137
 
</div>
138
 
</div>
139
 
<div class="section" id="start-improving-this-plugin-in-30-seconds">
140
 
<h1>Start improving this plugin in 30 seconds</h1>
141
 
<ol class="arabic simple">
142
 
<li>Download <a class="reference external" href="http://bitbucket.org/hpk42/py-trunk/raw/1.1.0b1/py/test/plugin/pytest_xfail.py">pytest_xfail.py</a> plugin source code</li>
143
 
<li>put it somewhere as <tt class="docutils literal"><span class="pre">pytest_xfail.py</span></tt> into your import path</li>
144
 
<li>a subsequent <tt class="docutils literal"><span class="pre">py.test</span></tt> run will use your local version</li>
145
 
</ol>
146
 
<p>Checkout <a class="reference external" href="../customize.html">customize</a>, other <a class="reference external" href="index.html">plugins</a> or <a class="reference external" href="../../contact.html">get in contact</a>.</p>
147
 
</div>
148
 
</div>
149
 
<script type="text/javascript">
150
 
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
151
 
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
152
 
</script>
153
 
<script type="text/javascript">
154
 
try {
155
 
var pageTracker = _gat._getTracker("UA-7597274-3");
156
 
pageTracker._trackPageview();
157
 
} catch(err) {}</script>
158
 
</body></html>
 
 
b'\\ No newline at end of file'