<!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>属性をもつテスト関数のマーク</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="recwarn.html" /> <link rel="prev" title="skip と xfail: 成功しないテストを扱う" href="skipping.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="recwarn.html" title="非推奨の警告やその他の警告のアサート" accesskey="N">次へ</a> |</li> <li class="right" > <a href="skipping.html" title="skip と xfail: 成功しないテストを扱う" accesskey="P">前へ</a> |</li> <li><a href="contents.html">pytest-2.2.4.0</a> »</li> <li><a href="apiref.html" accesskey="U">py.test リファレンスドキュメント</a> »</li> </ul> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="contents.html">目次</a></h3> <ul> <li><a class="reference internal" href="#">属性をもつテスト関数のマーク</a><ul> <li><a class="reference internal" href="#api">マーカー関連オブジェクトの API リファレンス</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="skipping.html" title="前の章へ">skip と xfail: 成功しないテストを扱う</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="recwarn.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="mark"> <span id="id1"></span><h1>属性をもつテスト関数のマーク<a class="headerlink" href="#mark" title="このヘッドラインへのパーマリンク">¶</a></h1> <p><tt class="docutils literal"><span class="pre">pytest.mark</span></tt> ヘルパーを使って、テスト関数にメタデータを簡単に設定できます。組み込みのマーカーを紹介します:</p> <ul class="simple"> <li><a class="reference internal" href="skipping.html#skipif"><em>skipif</em></a>: 特定の条件を満たした場合にテスト関数をスキップ</li> <li><a class="reference internal" href="skipping.html#xfail"><em>xfail</em></a>: 特定の条件を満たした場合に “失敗を期待”</li> <li><a class="reference internal" href="example/parametrize.html#parametrizemark"><em>parametrize</em></a>: 同じテスト関数に対して複数回の呼び出しを実行</li> </ul> <p>カスタムマーカーを作成する、または全体のテストクラスやモジュールにマーカーを適用するのは簡単です。ドキュメントでもある <a class="reference internal" href="example/markers.html#mark-examples"><em>カスタムマーカーを使う</em></a> のサンプルを参照してください。</p> <div class="section" id="api"> <h2>マーカー関連オブジェクトの API リファレンス<a class="headerlink" href="#api" title="このヘッドラインへのパーマリンク">¶</a></h2> <dl class="class"> <dt id="_pytest.mark.MarkGenerator"> <em class="property">class </em><tt class="descclassname">_pytest.mark.</tt><tt class="descname">MarkGenerator</tt><a class="reference internal" href="_modules/_pytest/mark.html#MarkGenerator"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.mark.MarkGenerator" title="この定義へのパーマリンク">¶</a></dt> <dd><p>Factory for <a class="reference internal" href="#_pytest.mark.MarkDecorator" title="_pytest.mark.MarkDecorator"><tt class="xref py py-class docutils literal"><span class="pre">MarkDecorator</span></tt></a> objects - exposed as a <tt class="docutils literal"><span class="pre">py.test.mark</span></tt> singleton instance. Example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">py</span> <span class="nd">@py.test.mark.slowtest</span> <span class="k">def</span> <span class="nf">test_function</span><span class="p">():</span> <span class="k">pass</span> </pre></div> </div> <p>will set a ‘slowtest’ <a class="reference internal" href="#_pytest.mark.MarkInfo" title="_pytest.mark.MarkInfo"><tt class="xref py py-class docutils literal"><span class="pre">MarkInfo</span></tt></a> object on the <tt class="docutils literal"><span class="pre">test_function</span></tt> object.</p> </dd></dl> <dl class="class"> <dt id="_pytest.mark.MarkDecorator"> <em class="property">class </em><tt class="descclassname">_pytest.mark.</tt><tt class="descname">MarkDecorator</tt><big>(</big><em>name</em>, <em>args=None</em>, <em>kwargs=None</em><big>)</big><a class="reference internal" href="_modules/_pytest/mark.html#MarkDecorator"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.mark.MarkDecorator" title="この定義へのパーマリンク">¶</a></dt> <dd><p>A decorator for test functions and test classes. When applied it will create <a class="reference internal" href="#_pytest.mark.MarkInfo" title="_pytest.mark.MarkInfo"><tt class="xref py py-class docutils literal"><span class="pre">MarkInfo</span></tt></a> objects which may be <a class="reference internal" href="example/simple.html#excontrolskip"><em>retrieved by hooks as item keywords</em></a>. MarkDecorator instances are often created like this:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">mark1</span> <span class="o">=</span> <span class="n">py</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">mark</span><span class="o">.</span><span class="n">NAME</span> <span class="c"># simple MarkDecorator</span> <span class="n">mark2</span> <span class="o">=</span> <span class="n">py</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">mark</span><span class="o">.</span><span class="n">NAME</span><span class="p">(</span><span class="n">name1</span><span class="o">=</span><span class="n">value</span><span class="p">)</span> <span class="c"># parametrized MarkDecorator</span> </pre></div> </div> <p>and can then be applied as decorators to test functions:</p> <div class="highlight-python"><div class="highlight"><pre><span class="nd">@mark2</span> <span class="k">def</span> <span class="nf">test_function</span><span class="p">():</span> <span class="k">pass</span> </pre></div> </div> </dd></dl> <dl class="class"> <dt id="_pytest.mark.MarkInfo"> <em class="property">class </em><tt class="descclassname">_pytest.mark.</tt><tt class="descname">MarkInfo</tt><big>(</big><em>name</em>, <em>args</em>, <em>kwargs</em><big>)</big><a class="reference internal" href="_modules/_pytest/mark.html#MarkInfo"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.mark.MarkInfo" title="この定義へのパーマリンク">¶</a></dt> <dd><p>Marking object created by <a class="reference internal" href="#_pytest.mark.MarkDecorator" title="_pytest.mark.MarkDecorator"><tt class="xref py py-class docutils literal"><span class="pre">MarkDecorator</span></tt></a> instances.</p> <dl class="method"> <dt id="_pytest.mark.MarkInfo.add"> <tt class="descname">add</tt><big>(</big><em>args</em>, <em>kwargs</em><big>)</big><a class="reference internal" href="_modules/_pytest/mark.html#MarkInfo.add"><span class="viewcode-link">[ソース]</span></a><a class="headerlink" href="#_pytest.mark.MarkInfo.add" title="この定義へのパーマリンク">¶</a></dt> <dd><p>add a MarkInfo with the given args and kwargs.</p> </dd></dl> <dl class="attribute"> <dt id="_pytest.mark.MarkInfo.args"> <tt class="descname">args</tt><em class="property"> = None</em><a class="headerlink" href="#_pytest.mark.MarkInfo.args" title="この定義へのパーマリンク">¶</a></dt> <dd><p>positional argument list, empty if none specified</p> </dd></dl> <dl class="attribute"> <dt id="_pytest.mark.MarkInfo.kwargs"> <tt class="descname">kwargs</tt><em class="property"> = None</em><a class="headerlink" href="#_pytest.mark.MarkInfo.kwargs" title="この定義へのパーマリンク">¶</a></dt> <dd><p>keyword argument dictionary, empty if nothing specified</p> </dd></dl> <dl class="attribute"> <dt id="_pytest.mark.MarkInfo.name"> <tt class="descname">name</tt><em class="property"> = None</em><a class="headerlink" href="#_pytest.mark.MarkInfo.name" title="この定義へのパーマリンク">¶</a></dt> <dd><p>name of attribute</p> </dd></dl> </dd></dl> </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="recwarn.html" title="非推奨の警告やその他の警告のアサート" >次へ</a> |</li> <li class="right" > <a href="skipping.html" title="skip と xfail: 成功しないテストを扱う" >前へ</a> |</li> <li><a href="contents.html">pytest-2.2.4.0</a> »</li> <li><a href="apiref.html" >py.test リファレンスドキュメント</a> »</li> </ul> </div> <div class="footer"> © Copyright 2011, holger krekel et alii. このドキュメントは <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3 で生成しました。 </div> </body> </html>