Sophie

Sophie

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

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>テスト関数 (funcargs) にオブジェクトを注入</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="拡張された xUnit スタイルのセットアップフィクスチャ" href="xunit_setup.html" />
    <link rel="prev" title="テストのアサーションにおける書き込みとレポート" href="assert.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="xunit_setup.html" title="拡張された xUnit スタイルのセットアップフィクスチャ"
             accesskey="N">次へ</a> |</li>
        <li class="right" >
          <a href="assert.html" title="テストのアサーションにおける書き込みとレポート"
             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="#">テスト関数 (funcargs) にオブジェクトを注入</a><ul>
<li><a class="reference internal" href="#funcarg-mechanism">関数の引数を使った依存性の注入</a><ul>
<li><a class="reference internal" href="#funcarg">基本的な注入の例</a></li>
</ul>
</li>
<li><a class="reference internal" href="#funcarg-request">funcarg <strong>request</strong> オブジェクト</a></li>
<li><a class="reference internal" href="#parametrized-test-functions">パラメーター化したテスト関数の複数呼び出し</a><ul>
<li><a class="reference internal" href="#id6">テストを生成する基本的な例</a></li>
<li><a class="reference internal" href="#metafunc"><strong>metafunc</strong> オブジェクト</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>前のトピックへ</h4>
  <p class="topless"><a href="assert.html"
                        title="前の章へ">テストのアサーションにおける書き込みとレポート</a></p>
  <h4>次のトピックへ</h4>
  <p class="topless"><a href="xunit_setup.html"
                        title="次の章へ">拡張された xUnit スタイルのセットアップフィクスチャ</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="funcargs">
<h1>テスト関数 (funcargs) にオブジェクトを注入<a class="headerlink" href="#funcargs" title="このヘッドラインへのパーマリンク">¶</a></h1>
<div class="section" id="funcarg-mechanism">
<span id="id1"></span><span id="id2"></span><h2>関数の引数を使った依存性の注入<a class="headerlink" href="#funcarg-mechanism" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>py.test は、テスト関数にオブジェクトを注入し、テストの実行に関連付けてそのライフサイクルを細かく制御できます。さらに別のオブジェクトでテスト関数を複数回実行することもできます。</p>
<p>オブジェクトを注入するための基本的な仕組みは <em>funcarg 機構</em> とも呼ばれます。ある引数に対して、その引数を受け取るテスト関数が呼ばれることで最終的にオブジェクトが注入されるからです。古典的な xUnit のやり方とは異なり <em>funcargs</em> は <a class="reference external" href="http://en.wikipedia.org/wiki/Dependency_injection">依存性の注入</a> に密接に関連したものです。その根拠は、テストコードを実行するために必要なオブジェクトからテストコードを分離するのに役立つからです。</p>
<p>テスト関数へ渡される値を作成するために、テスト関数のコンテキストに対してフルアクセスをもったファクトリー関数が呼ばれます。そして、ファイナライザーを登録したり、ライフサイクルキャッシュヘルパーを実行します。ファクトリー関数は、同じテストクラスかテストモジュール、ディレクトリ毎の <tt class="docutils literal"><span class="pre">conftest.py</span></tt> ファイル、外部プラグインであろうと、そのいずれでも実装できます。これにより、テストの実行に必要なテストコードとオブジェクトを完全に分離できます。</p>
<p>テスト関数は、 <a class="reference internal" href="#parametrizing-tests"><em>パラメーターテスト</em></a> で説明したようなケースなら複数回呼び出すこともあります。これは、例えば、別々のデータベースのバックエンド、または複数の数値の引数セットをテストしたいときや、テスト関数の同じセットを再利用したいといったときにとても便利です。</p>
<p>py.test には <a class="reference internal" href="builtin.html#builtinfuncargs"><em>組み込み関数の引数</em></a> が付属していて、そのサンプルを紹介する節に洗練された利用方法があります。</p>
<div class="section" id="funcarg">
<span id="id4"></span><h3>基本的な注入の例<a class="headerlink" href="#funcarg" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>簡単な自己完結型のテストモジュールを見てみましょう:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># ./test_simplefactory.py の内容</span>
<span class="k">def</span> <span class="nf">pytest_funcarg__myfuncarg</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="k">return</span> <span class="mi">42</span>

<span class="k">def</span> <span class="nf">test_function</span><span class="p">(</span><span class="n">myfuncarg</span><span class="p">):</span>
    <span class="k">assert</span> <span class="n">myfuncarg</span> <span class="o">==</span> <span class="mi">17</span>
</pre></div>
</div>
<p>このテスト関数は <tt class="docutils literal"><span class="pre">myfuncarg</span></tt> という名前のオブジェクトへの注入を必要とします。この場合 py.test は、同じモジュール内の <tt class="docutils literal"><span class="pre">pytest_funcarg__myfuncarg</span></tt> というファクトリー関数を見つけて呼び出します。</p>
<p>次のようにテストが実行されます:</p>
<div class="highlight-python"><pre>$ py.test test_simplefactory.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.1 -- pytest-2.2.4
collecting ... collected 1 items

test_simplefactory.py F

================================= FAILURES =================================
______________________________ test_function _______________________________

myfuncarg = 42

    def test_function(myfuncarg):
&gt;       assert myfuncarg == 17
E       assert 42 == 17

test_simplefactory.py:5: AssertionError
========================= 1 failed in 0.01 seconds =========================</pre>
</div>
<p>これは実際にテスト関数が <tt class="docutils literal"><span class="pre">myfuncarg</span></tt> 引数の値が <tt class="docutils literal"><span class="pre">42</span></tt> で呼び出されて、そのアサートに失敗します。py.test がどういった手順でテスト関数を呼び出すかを説明します:</p>
<ol class="arabic simple">
<li>py.test は <tt class="docutils literal"><span class="pre">test_</span></tt> という接頭辞をもつ <tt class="docutils literal"><span class="pre">test_function</span></tt> を <a class="reference internal" href="goodpractises.html#test-discovery"><em>探索します</em></a> 。テスト関数は <tt class="docutils literal"><span class="pre">myfuncarg</span></tt> という関数の引数を必要とします。 <tt class="docutils literal"><span class="pre">pytest_funcarg__myfuncarg</span></tt> という名前を調べて一致するファクトリー関数が検出されます。</li>
</ol>
<ol class="arabic simple" start="2">
<li><tt class="docutils literal"><span class="pre">pytest_funcarg__myfuncarg(request)</span></tt> が呼び出されて <tt class="docutils literal"><span class="pre">myfuncarg</span></tt> の値を返します。</li>
</ol>
<ol class="arabic simple" start="3">
<li>そのテスト関数は <tt class="docutils literal"><span class="pre">test_function(42)</span></tt> として呼び出されます。この実行結果は、アサーションが不一致なので上述した例外を発生させます。</li>
</ol>
<p>関数の引数に誤字があったり、利用できないものを使おうとしたら、利用できる関数の引数の一覧と共にエラーが表示されるので注意してください。</p>
<p>いつでも次のようにして:</p>
<div class="highlight-python"><pre>py.test --fixtures test_simplefactory.py</pre>
</div>
<p>利用できる関数の引数 (&#8220;リソース&#8221; とも見なせる) を調べられます。</p>
</div>
</div>
<div class="section" id="funcarg-request">
<span id="factory"></span><span id="fixture-function"></span><h2>funcarg <strong>request</strong> オブジェクト<a class="headerlink" href="#funcarg-request" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>funcarg ファクトリー関数は、特別なテスト関数呼び出しに関連付けられた <strong>request</strong> オブジェクトを受け取ります。request オブジェクトは funcarg ファクトリーへ渡されて、テスト設定とコンテキストへのアクセスを提供します:</p>
<dl class="class">
<dt id="_pytest.python.FixtureRequest">
<em class="property">class </em><tt class="descclassname">_pytest.python.</tt><tt class="descname">FixtureRequest</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>A request for a fixture from a test or fixture function.</p>
<p>A request object gives access to the requesting test context
and has an optional <tt class="docutils literal"><span class="pre">param</span></tt> attribute in case
the fixture is parametrized indirectly.</p>
<dl class="attribute">
<dt id="_pytest.python.FixtureRequest.function">
<tt class="descname">function</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.function"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.function" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>test function object if the request has a per-function scope.</p>
</dd></dl>

<dl class="attribute">
<dt id="_pytest.python.FixtureRequest.cls">
<tt class="descname">cls</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.cls"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.cls" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>class (can be None) where the test function was collected.</p>
</dd></dl>

<dl class="attribute">
<dt id="_pytest.python.FixtureRequest.module">
<tt class="descname">module</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.module"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.module" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>python module object where the test function was collected.</p>
</dd></dl>

<dl class="attribute">
<dt id="_pytest.python.FixtureRequest.keywords">
<tt class="descname">keywords</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.keywords"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.keywords" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>keywords/markers dictionary for the underlying node.</p>
</dd></dl>

<dl class="attribute">
<dt id="_pytest.python.FixtureRequest.config">
<tt class="descname">config</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.config"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.config" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>the pytest config object associated with this request.</p>
</dd></dl>

</dd></dl>

<span class="target" id="useful-caching-and-finalization-helpers"></span><dl class="method">
<dt id="_pytest.python.FixtureRequest.addfinalizer">
<tt class="descclassname">FixtureRequest.</tt><tt class="descname">addfinalizer</tt><big>(</big><em>finalizer</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.addfinalizer"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.addfinalizer" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>add finalizer/teardown function to be called after the
last test within the requesting test context finished
execution.</p>
</dd></dl>

<dl class="method">
<dt id="_pytest.python.FixtureRequest.cached_setup">
<tt class="descclassname">FixtureRequest.</tt><tt class="descname">cached_setup</tt><big>(</big><em>setup</em>, <em>teardown=None</em>, <em>scope='module'</em>, <em>extrakey=None</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.cached_setup"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.cached_setup" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>(deprecated) Return a testing resource managed by <tt class="docutils literal"><span class="pre">setup</span></tt> &amp;
<tt class="docutils literal"><span class="pre">teardown</span></tt> calls.  <tt class="docutils literal"><span class="pre">scope</span></tt> and <tt class="docutils literal"><span class="pre">extrakey</span></tt> determine when the
<tt class="docutils literal"><span class="pre">teardown</span></tt> function will be called so that subsequent calls to
<tt class="docutils literal"><span class="pre">setup</span></tt> would recreate the resource.  With pytest-2.3 you often
do not need <tt class="docutils literal"><span class="pre">cached_setup()</span></tt> as you can directly declare a scope
on a fixture function and register a finalizer through
<tt class="docutils literal"><span class="pre">request.addfinalizer()</span></tt>.</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>teardown</strong> &#8211; function receiving a previously setup resource.</li>
<li><strong>setup</strong> &#8211; a no-argument function creating a resource.</li>
<li><strong>scope</strong> &#8211; a string value out of <tt class="docutils literal"><span class="pre">function</span></tt>, <tt class="docutils literal"><span class="pre">class</span></tt>, <tt class="docutils literal"><span class="pre">module</span></tt>
or <tt class="docutils literal"><span class="pre">session</span></tt> indicating the caching lifecycle of the resource.</li>
<li><strong>extrakey</strong> &#8211; added to internal caching key of (funcargname, scope).</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="_pytest.python.FixtureRequest.applymarker">
<tt class="descclassname">FixtureRequest.</tt><tt class="descname">applymarker</tt><big>(</big><em>marker</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.applymarker"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.applymarker" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>Apply a marker to a single test function invocation.
This method is useful if you don&#8217;t want to have a keyword/marker
on all function invocations.</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>marker</strong> &#8211; a <a class="reference internal" href="mark.html#_pytest.mark.MarkDecorator" title="_pytest.mark.MarkDecorator"><tt class="xref py py-class docutils literal"><span class="pre">_pytest.mark.MarkDecorator</span></tt></a> object
created by a call to <tt class="docutils literal"><span class="pre">py.test.mark.NAME(...)</span></tt>.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="_pytest.python.FixtureRequest.getfuncargvalue">
<tt class="descclassname">FixtureRequest.</tt><tt class="descname">getfuncargvalue</tt><big>(</big><em>argname</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.getfuncargvalue"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.getfuncargvalue" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>Dynamically retrieve a named fixture function argument.</p>
<p>As of pytest-2.3, it is easier and usually better to access other
fixture values by stating it as an input argument in the fixture
function.  If you only can decide about using another fixture at test
setup time, you may use this function to retrieve it inside a fixture
function body.</p>
</dd></dl>

</div>
<div class="section" id="parametrized-test-functions">
<span id="parametrizing-tests"></span><span id="test-generators"></span><span id="id5"></span><h2>パラメーター化したテスト関数の複数呼び出し<a class="headerlink" href="#parametrized-test-functions" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>別の関数の引数の値を取って呼び出す新たなテスト関数を追加することで、同じテスト関数に対して複数回の実行をパラメーター化して実行できます。簡単な自己完結型のサンプルコードを見てみましょう:</p>
<div class="section" id="id6">
<h3>テストを生成する基本的な例<a class="headerlink" href="#id6" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>同じテスト関数に対する複数回呼び出しに生成する <tt class="docutils literal"><span class="pre">pytest_generate_tests</span></tt> フックを使うテストモジュールを見てみましょう:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># test_example.py の内容</span>
<span class="k">def</span> <span class="nf">pytest_generate_tests</span><span class="p">(</span><span class="n">metafunc</span><span class="p">):</span>
    <span class="k">if</span> <span class="s">&quot;numiter&quot;</span> <span class="ow">in</span> <span class="n">metafunc</span><span class="o">.</span><span class="n">fixturenames</span><span class="p">:</span>
        <span class="n">metafunc</span><span class="o">.</span><span class="n">parametrize</span><span class="p">(</span><span class="s">&quot;numiter&quot;</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span>

<span class="k">def</span> <span class="nf">test_func</span><span class="p">(</span><span class="n">numiter</span><span class="p">):</span>
    <span class="k">assert</span> <span class="n">numiter</span> <span class="o">&lt;</span> <span class="mi">9</span>
</pre></div>
</div>
<p>このサンプルコードを実行すると <tt class="docutils literal"><span class="pre">range(10)</span></tt> のリストの要素を1つずつ引数に渡す <tt class="docutils literal"><span class="pre">test_func</span></tt> を10回実行します:</p>
<div class="highlight-python"><pre>$ py.test test_example.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.1 -- pytest-2.2.4
collecting ... collected 10 items

test_example.py .........F

================================= FAILURES =================================
_______________________________ test_func[9] _______________________________

numiter = 9

    def test_func(numiter):
&gt;       assert numiter &lt; 9
E       assert 9 &lt; 9

test_example.py:6: AssertionError
==================== 1 failed, 9 passed in 0.02 seconds ====================</pre>
</div>
<p>分かりやすいように <tt class="docutils literal"><span class="pre">numiter</span></tt> の値が <tt class="docutils literal"><span class="pre">9</span></tt> のときのみテストが失敗します。 <tt class="docutils literal"><span class="pre">pytest_generate_tests(metafunc)</span></tt> フックは、実際にテストを実行するときとは違うフェーズの、テストコレクションで呼ばれることに注意してください。では、テストコレクションがどうなるかをちょっと見てみましょう:</p>
<div class="highlight-python"><pre>$ py.test --collectonly test_example.py
=========================== test session starts ============================
platform linux2 -- Python 2.7.1 -- pytest-2.2.4
collecting ... collected 10 items
&lt;Module 'test_example.py'&gt;
  &lt;Function 'test_func[0]'&gt;
  &lt;Function 'test_func[1]'&gt;
  &lt;Function 'test_func[2]'&gt;
  &lt;Function 'test_func[3]'&gt;
  &lt;Function 'test_func[4]'&gt;
  &lt;Function 'test_func[5]'&gt;
  &lt;Function 'test_func[6]'&gt;
  &lt;Function 'test_func[7]'&gt;
  &lt;Function 'test_func[8]'&gt;
  &lt;Function 'test_func[9]'&gt;

=============================  in 0.00 seconds =============================</pre>
</div>
<p>テスト実行時に <tt class="docutils literal"><span class="pre">7</span></tt> の値が渡されるときだけ実行したい場合は次のようにして行います:</p>
<div class="highlight-python"><pre>$ py.test -v -k 7 test_example.py  # または -k test_func[7]
=========================== test session starts ============================
platform linux2 -- Python 2.7.1 -- pytest-2.2.4 -- /home/hpk/venv/0/bin/python
collecting ... collected 10 items

test_example.py:5: test_func[7] PASSED

======================= 9 tests deselected by '-k7' ========================
================== 1 passed, 9 deselected in 0.01 seconds ==================</pre>
</div>
<p><a class="reference internal" href="example/parametrize.html#paramexamples"><em>さらにパラメーターテストのサンプル</em></a> を見たくなりますね。</p>
</div>
<div class="section" id="metafunc">
<span id="metafunc-object"></span><h3><strong>metafunc</strong> オブジェクト<a class="headerlink" href="#metafunc" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>metafunc オブジェクトは <tt class="docutils literal"><span class="pre">pytest_generate_tests</span></tt> フックへ渡されます。これはテスト関数を検査したり、テスト設定またはテスト関数が定義されているクラスやモジュールで指定された値を取るテストを生成するのに役立ちます:</p>
<p><tt class="docutils literal"><span class="pre">metafunc.fixturenames</span></tt>: テスト関数へ渡される引数セット</p>
<p><tt class="docutils literal"><span class="pre">metafunc.function</span></tt>: 対象となる Python のテスト関数</p>
<p><tt class="docutils literal"><span class="pre">metafunc.cls</span></tt>: テスト関数が定義されているところのクラスオブジェクト、または None</p>
<p><tt class="docutils literal"><span class="pre">metafunc.module</span></tt>: テスト関数が定義されているところのモジュールオブジェクト</p>
<p><tt class="docutils literal"><span class="pre">metafunc.config</span></tt>: コマンドラインオプションと汎用的な設定オブジェクト</p>
<dl class="method">
<dt id="_pytest.python.Metafunc.parametrize">
<tt class="descclassname">Metafunc.</tt><tt class="descname">parametrize</tt><big>(</big><em>argnames</em>, <em>argvalues</em>, <em>indirect=False</em>, <em>ids=None</em>, <em>scope=None</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#Metafunc.parametrize"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.Metafunc.parametrize" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>Add new invocations to the underlying test function using the list
of argvalues for the given argnames.  Parametrization is performed
during the collection phase.  If you need to setup expensive resources
see about setting indirect=True to do it rather at test setup time.</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>argnames</strong> &#8211; an argument name or a list of argument names</li>
<li><strong>argvalues</strong> &#8211; The list of argvalues determines how often a test is invoked
with different argument values.  If only one argname was specified argvalues
is a list of simple values.  If N argnames were specified, argvalues must
be a list of N-tuples, where each tuple-element specifies a value for its
respective argname.</li>
<li><strong>indirect</strong> &#8211; if True each argvalue corresponding to an argname will
be passed as request.param to its respective argname fixture
function so that it can perform more expensive setups during the
setup phase of a test rather than at collection time.</li>
<li><strong>ids</strong> &#8211; list of string ids each corresponding to the argvalues so
that they are part of the test id. If no ids are provided they will
be generated automatically from the argvalues.</li>
<li><strong>scope</strong> &#8211; if specified it denotes the scope of the parameters.
The scope is used for grouping tests by parameter instances.
It will also override any fixture-function defined scope, allowing
to set a dynamic scope using test context or configuration.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="_pytest.python.Metafunc.addcall">
<tt class="descclassname">Metafunc.</tt><tt class="descname">addcall</tt><big>(</big><em>funcargs=None</em>, <em>id=_notexists</em>, <em>param=_notexists</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#Metafunc.addcall"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.python.Metafunc.addcall" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>(deprecated, use parametrize) Add a new call to the underlying
test function during the collection phase of a test run.  Note that
request.addcall() is called during the test collection phase prior and
independently to actual test execution.  You should only use addcall()
if you need to specify multiple arguments of a test function.</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>funcargs</strong> &#8211; argument keyword dictionary used when invoking
the test function.</li>
<li><strong>id</strong> &#8211; used for reporting and identification purposes.  If you
don&#8217;t supply an <cite>id</cite> an automatic unique id will be generated.</li>
<li><strong>param</strong> &#8211; a parameter which will be exposed to a later fixture function
invocation through the <tt class="docutils literal"><span class="pre">request.param</span></tt> attribute.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</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="xunit_setup.html" title="拡張された xUnit スタイルのセットアップフィクスチャ"
             >次へ</a> |</li>
        <li class="right" >
          <a href="assert.html" title="テストのアサーションにおける書き込みとレポート"
             >前へ</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>