Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 7f671eb35339cf812de52087b0d93519 > files > 379

python3-pytest-2.3.5-3.fc18.noarch.rpm



<!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>Pytest 組み込みヘルパー機能</title>
    
    <link rel="stylesheet" href="_static/sphinxdoc.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.2.4.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>
    <script type="text/javascript" src="_static/translations.js"></script>
    <link rel="top" title="None" href="index.html" />
    <link rel="up" title="py.test リファレンスドキュメント" href="apiref.html" />
    <link rel="next" title="基本的なテストの設定" href="customize.html" />
    <link rel="prev" title="py.test リファレンスドキュメント" href="apiref.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>ナビゲーション</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="py-modindex.html" title="Pythonモジュール索引"
             >モジュール</a></li>
        <li class="right" >
          <a href="customize.html" title="基本的なテストの設定"
             accesskey="N">次へ</a> |</li>
        <li class="right" >
          <a href="apiref.html" title="py.test リファレンスドキュメント"
             accesskey="P">前へ</a> |</li>
        <li><a href="contents.html">pytest-2.2.4.0</a> &raquo;</li>
          <li><a href="apiref.html" accesskey="U">py.test リファレンスドキュメント</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="contents.html">目次</a></h3>
  <ul>
<li><a class="reference internal" href="#">Pytest 組み込みヘルパー機能</a><ul>
<li><a class="reference internal" href="#id1">組み込みの pytest.* 関数とヘルパーオブジェクト</a></li>
<li><a class="reference internal" href="#builtinfuncargs">組み込み関数の引数</a></li>
</ul>
</li>
</ul>

  <h4>前のトピックへ</h4>
  <p class="topless"><a href="apiref.html"
                        title="前の章へ">py.test リファレンスドキュメント</a></p>
  <h4>次のトピックへ</h4>
  <p class="topless"><a href="customize.html"
                        title="次の章へ">基本的なテストの設定</a></p>
<div id="searchbox" style="display: none">
  <h3>クイック検索</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="検索" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    モジュール、クラス、または関数名を入力してください
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="pytest">
<span id="pytest-helpers"></span><h1>Pytest 組み込みヘルパー機能<a class="headerlink" href="#pytest" title="このヘッドラインへのパーマリンク">¶</a></h1>
<div class="section" id="id1">
<h2>組み込みの pytest.* 関数とヘルパーオブジェクト<a class="headerlink" href="#id1" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>Python インタープリターの対話モードから次のように入力すると:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">pytest</span>
<span class="n">help</span><span class="p">(</span><span class="n">pytest</span><span class="p">)</span>
</pre></div>
</div>
<p>グローバルに利用できるヘルパー機能の概要を把握できます。</p>
<span class="target" id="module-pytest"></span><p>pytest: unit and functional testing with Python.</p>
<dl class="function">
<dt id="pytest.main">
<tt class="descclassname">pytest.</tt><tt class="descname">main</tt><big>(</big><em>args=None</em>, <em>plugins=None</em><big>)</big><a class="headerlink" href="#pytest.main" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>return exit code, after performing an in-process test run.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">パラメタ:</th><td class="field-body"><ul class="first last simple">
<li><strong>args</strong> &#8211; list of command line arguments.</li>
<li><strong>plugins</strong> &#8211; list of plugin objects to be auto-registered during
initialization.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="pytest.fail">
<tt class="descclassname">pytest.</tt><tt class="descname">fail</tt><big>(</big><em>msg=''</em>, <em>pytrace=True</em><big>)</big><a class="headerlink" href="#pytest.fail" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>explicitely fail an currently-executing test with the given Message.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">パラメタ:</th><td class="field-body"><strong>pytrace</strong> &#8211; if false the msg represents the full failure information
and no python traceback will be reported.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="pytest.skip">
<tt class="descclassname">pytest.</tt><tt class="descname">skip</tt><big>(</big><em>msg=''</em><big>)</big><a class="headerlink" href="#pytest.skip" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>skip an executing test with the given message.  Note: it&#8217;s usually
better to use the py.test.mark.skipif marker to declare a test to be
skipped under certain conditions like mismatching platforms or
dependencies.  See the pytest_skipping plugin for details.</p>
</dd></dl>

<dl class="function">
<dt id="pytest.exit">
<tt class="descclassname">pytest.</tt><tt class="descname">exit</tt><big>(</big><em>msg</em><big>)</big><a class="headerlink" href="#pytest.exit" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>exit testing process as if KeyboardInterrupt was triggered.</p>
</dd></dl>

<dl class="function">
<dt id="pytest.importorskip">
<tt class="descclassname">pytest.</tt><tt class="descname">importorskip</tt><big>(</big><em>modname</em>, <em>minversion=None</em><big>)</big><a class="headerlink" href="#pytest.importorskip" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>return imported module if it has a higher __version__ than the
optionally specified &#8216;minversion&#8217; - otherwise call py.test.skip()
with a message detailing the mismatch.</p>
</dd></dl>

<dl class="function">
<dt id="pytest.fixture">
<tt class="descclassname">pytest.</tt><tt class="descname">fixture</tt><big>(</big><em>scope='function'</em>, <em>params=None</em>, <em>autouse=False</em><big>)</big><a class="headerlink" href="#pytest.fixture" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>(return a) decorator to mark a fixture factory function.</p>
<p>This decorator can be used (with or or without parameters) to define
a fixture function.  The name of the fixture function can later be
referenced to cause its invocation ahead of running tests: test
modules or classes can use the pytest.mark.usefixtures(fixturename)
marker.  Test functions can directly use fixture names as input
arguments in which case the fixture instance returned from the fixture
function will be injected.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">パラメタ:</th><td class="field-body"><ul class="first last simple">
<li><strong>scope</strong> &#8211; the scope for which this fixture is shared, one of
&#8220;function&#8221; (default), &#8220;class&#8221;, &#8220;module&#8221;, &#8220;session&#8221;.</li>
<li><strong>params</strong> &#8211; an optional list of parameters which will cause multiple
invocations of the fixture function and all of the tests
using it.</li>
<li><strong>autouse</strong> &#8211; if True, the fixture func is activated for all tests that
can see it.  If False (the default) then an explicit
reference is needed to activate the fixture.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="pytest.raises">
<tt class="descclassname">pytest.</tt><tt class="descname">raises</tt><big>(</big><em>ExpectedException</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pytest.raises" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>assert that a code block/function call raises &#64;ExpectedException
and raise a failure exception otherwise.</p>
<p>If using Python 2.5 or above, you may use this function as a
context manager:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">):</span>
<span class="gp">... </span>   <span class="mi">1</span><span class="o">/</span><span class="mi">0</span>
</pre></div>
</div>
<p>Or you can specify a callable by passing a to-be-called lambda:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="mi">1</span><span class="o">/</span><span class="mi">0</span><span class="p">)</span>
<span class="go">&lt;ExceptionInfo ...&gt;</span>
</pre></div>
</div>
<p>or you can specify an arbitrary callable with arguments:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> <span class="k">return</span> <span class="mi">1</span><span class="o">/</span><span class="n">x</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">&lt;ExceptionInfo ...&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="go">&lt;ExceptionInfo ...&gt;</span>
</pre></div>
</div>
<p>A third possibility is to use a string to be executed:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">,</span> <span class="s">&quot;f(0)&quot;</span><span class="p">)</span>
<span class="go">&lt;ExceptionInfo ...&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="pytest.xfail">
<tt class="descclassname">pytest.</tt><tt class="descname">xfail</tt><big>(</big><em>reason=''</em><big>)</big><a class="headerlink" href="#pytest.xfail" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>xfail an executing test or setup functions with the given reason.</p>
</dd></dl>

<dl class="function">
<dt id="pytest.deprecated_call">
<tt class="descclassname">pytest.</tt><tt class="descname">deprecated_call</tt><big>(</big><em>func</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pytest.deprecated_call" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>assert that calling <tt class="docutils literal"><span class="pre">func(*args,</span> <span class="pre">**kwargs)</span></tt>
triggers a DeprecationWarning.</p>
</dd></dl>

</div>
<div class="section" id="builtinfuncargs">
<span id="id2"></span><h2>組み込み関数の引数<a class="headerlink" href="#builtinfuncargs" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>次のように入力して、利用できる組み込みまたはプロジェクトカスタムの <a class="reference internal" href="funcargs.html#id1"><em>関数の引数</em></a> を確認できます。</p>
<blockquote>
<div><div class="line-block">
<div class="line">$ py.test &#8211;fixtures</div>
<div class="line">====================== test session starts =======================</div>
<div class="line">platform linux2 &#8211; Python 2.7.1 &#8211; pytest-2.2.4</div>
<div class="line">collected 0 items</div>
<div class="line">pytestconfig</div>
<div class="line-block">
<div class="line">pytest の config オブジェクトとコマンドラインオプションへのアクセス</div>
<div class="line"><br /></div>
</div>
<div class="line">capsys</div>
<div class="line-block">
<div class="line">sys.stdout/sys.stderr への書き込み内容を取得できる</div>
<div class="line">キャプチャした出力内容は <tt class="docutils literal"><span class="pre">(out,</span> <span class="pre">err)</span></tt> のタプルを返す</div>
<div class="line"><tt class="docutils literal"><span class="pre">capsys.readouterr()</span></tt> メソッドで利用できる</div>
<div class="line"><br /></div>
</div>
<div class="line">capfd</div>
<div class="line-block">
<div class="line">ファイルディスクリプタ 1 と 2 へ書き込み内容を取得できる</div>
<div class="line">キャプチャした出力内容は <tt class="docutils literal"><span class="pre">(out,</span> <span class="pre">err)</span></tt> のタプルを返す</div>
<div class="line"><tt class="docutils literal"><span class="pre">capsys.readouterr()</span></tt> メソッドで利用できる</div>
<div class="line"><br /></div>
</div>
<div class="line">tmpdir</div>
<div class="line-block">
<div class="line">基本となる一時ディレクトリ配下にサブディレクトリを作成して、</div>
<div class="line">テスト関数の実行毎に一意な一時ディレクトリのオブジェクトを返す</div>
<div class="line">これは py.path.local のパスオブジェクトが返される</div>
<div class="line"><br /></div>
</div>
<div class="line">monkeypatch</div>
<div class="line-block">
<div class="line">オブジェクト、ディクショナリ、os.environ を変更する</div>
<div class="line">次のヘルパーメソッドを提供する <tt class="docutils literal"><span class="pre">monkeypatch</span></tt> オブジェクトが返される</div>
<div class="line"><br /></div>
<div class="line">monkeypatch.setattr(obj, name, value, raising=True)</div>
<div class="line">monkeypatch.delattr(obj, name, raising=True)</div>
<div class="line">monkeypatch.setitem(mapping, name, value)</div>
<div class="line">monkeypatch.delitem(obj, name, raising=True)</div>
<div class="line">monkeypatch.setenv(name, value, prepend=False)</div>
<div class="line">monkeypatch.delenv(name, value, raising=True)</div>
<div class="line">monkeypatch.syspath_prepend(path)</div>
<div class="line">monkeypatch.chdir(path)</div>
<div class="line"><br /></div>
<div class="line">全ての変更はテスト関数の呼び出しが終わった後で元に戻ります</div>
<div class="line"><tt class="docutils literal"><span class="pre">raising</span></tt> パラメーターは、セット/削除の操作対象がないときに</div>
<div class="line">KeyError や AttributeError を発生させるかどうかを決めます</div>
<div class="line"><br /></div>
</div>
<div class="line">recwarn</div>
<div class="line-block">
<div class="line">次のメソッドを提供する WarningsRecorder インスタンスを返す</div>
<div class="line"><br /></div>
<div class="line">* <tt class="docutils literal"><span class="pre">pop(category=None)</span></tt>: category に一致する最後の警告を返す</div>
<div class="line">* <tt class="docutils literal"><span class="pre">clear()</span></tt>: 警告のリストを削除する</div>
<div class="line"><br /></div>
<div class="line">警告については <a class="reference external" href="http://docs.python.org/library/warnings.html">http://docs.python.org/library/warnings.html</a> を</div>
<div class="line">参照してください</div>
<div class="line"><br /></div>
</div>
<div class="line">========================  in 0.00 seconds ========================</div>
</div>
</div></blockquote>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>ナビゲーション</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="py-modindex.html" title="Pythonモジュール索引"
             >モジュール</a></li>
        <li class="right" >
          <a href="customize.html" title="基本的なテストの設定"
             >次へ</a> |</li>
        <li class="right" >
          <a href="apiref.html" title="py.test リファレンスドキュメント"
             >前へ</a> |</li>
        <li><a href="contents.html">pytest-2.2.4.0</a> &raquo;</li>
          <li><a href="apiref.html" >py.test リファレンスドキュメント</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2011, holger krekel et alii.
      このドキュメントは <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3 で生成しました。
    </div>
  </body>
</html>