Sophie

Sophie

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

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>基本的なテストの設定</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="assert.html" />
    <link rel="prev" title="Pytest 組み込みヘルパー機能" href="builtin.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="assert.html" title="テストのアサーションにおける書き込みとレポート"
             accesskey="N">次へ</a> |</li>
        <li class="right" >
          <a href="builtin.html" title="Pytest 組み込みヘルパー機能"
             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="#">基本的なテストの設定</a><ul>
<li><a class="reference internal" href="#id2">コマンドラインオプションと構成ファイルの設定</a></li>
<li><a class="reference internal" href="#ini">INI 構成ファイルからテスト設定の読み込み方法</a></li>
<li><a class="reference internal" href="#adding-default-options">コマンドラインオプションのデフォルト値の変更方法</a></li>
<li><a class="reference internal" href="#id4">組み込みの構成ファイルオプション</a></li>
</ul>
</li>
</ul>

  <h4>前のトピックへ</h4>
  <p class="topless"><a href="builtin.html"
                        title="前の章へ">Pytest 組み込みヘルパー機能</a></p>
  <h4>次のトピックへ</h4>
  <p class="topless"><a href="assert.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="id1">
<h1>基本的なテストの設定<a class="headerlink" href="#id1" title="このヘッドラインへのパーマリンク">¶</a></h1>
<div class="section" id="id2">
<h2>コマンドラインオプションと構成ファイルの設定<a class="headerlink" href="#id2" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>一般的なヘルプオプションを使って、ini スタイルの構成ファイルのコマンドラインオプションとその値のヘルプを確認できます:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">py</span><span class="o">.</span><span class="n">test</span> <span class="o">-</span><span class="n">h</span>   <span class="c"># オプションと構成ファイルの設定を表示</span>
</pre></div>
</div>
<p>これはインストール済みのプラグインが登録したコマンドライン設定と構成ファイル設定も表示します。</p>
</div>
<div class="section" id="ini">
<h2>INI 構成ファイルからテスト設定の読み込み方法<a class="headerlink" href="#ini" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>py.test は、コマンドライン引数のディレクトリとその上位ディレクトリの、最初に一致する ini スタイルの構成ファイルを検索します。次の順番でファイル名を見ていきます:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pytest</span><span class="o">.</span><span class="n">ini</span>
<span class="n">tox</span><span class="o">.</span><span class="n">ini</span>
<span class="n">setup</span><span class="o">.</span><span class="n">cfg</span>
</pre></div>
</div>
<p>最初の <tt class="docutils literal"><span class="pre">[pytest]</span></tt> のセクションを見つけたときに検索を中止します。複数の設定ファイルから設定値をマージするようなことはしません。サンプルを紹介します:</p>
<div class="highlight-python"><pre>py.test path/to/testdir</pre>
</div>
<p>次のように構成ファイルを含むディレクトリがあります:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">testdir</span><span class="o">/</span><span class="n">pytest</span><span class="o">.</span><span class="n">ini</span>
<span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">testdir</span><span class="o">/</span><span class="n">tox</span><span class="o">.</span><span class="n">ini</span>
<span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">testdir</span><span class="o">/</span><span class="n">setup</span><span class="o">.</span><span class="n">cfg</span>
<span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">pytest</span><span class="o">.</span><span class="n">ini</span>
<span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">tox</span><span class="o">.</span><span class="n">ini</span>
<span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">setup</span><span class="o">.</span><span class="n">cfg</span>
<span class="o">...</span> <span class="c"># ファイルシステムのルートまで上る</span>
</pre></div>
</div>
<p>引数が py.test を実行するために提供されるものなら、カレントディレクトリがその検索の開始位置に使われます。</p>
</div>
<div class="section" id="adding-default-options">
<span id="how-to-change-command-line-options-defaults"></span><span id="id3"></span><h2>コマンドラインオプションのデフォルト値の変更方法<a class="headerlink" href="#adding-default-options" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>py.test を使うときに毎回一連のコマンドラインオプションを入力するのは飽き飽きしてきます。例えば、毎回スキップしたり xfail したテストの詳細情報を見たいなら、進捗状況を簡潔な &#8220;ドット&#8221; 出力にするのと同様に、構成ファイル内にその設定を記述できます:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># pytest.ini の内容</span>
<span class="c"># (または tox.ini か setup.cfg)</span>
<span class="p">[</span><span class="n">pytest</span><span class="p">]</span>
<span class="n">addopts</span> <span class="o">=</span> <span class="o">-</span><span class="n">rsxX</span> <span class="o">-</span><span class="n">q</span>
</pre></div>
</div>
<p>設定後に実行すると <tt class="docutils literal"><span class="pre">py.test</span></tt> は指定したオプションを追加します。</p>
</div>
<div class="section" id="id4">
<h2>組み込みの構成ファイルオプション<a class="headerlink" href="#id4" title="このヘッドラインへのパーマリンク">¶</a></h2>
<dl class="confval">
<dt id="confval-minversion">
<tt class="descname">minversion</tt><a class="headerlink" href="#confval-minversion" title="この定義へのパーマリンク">¶</a></dt>
<dd><blockquote>
<div></div></blockquote>
<p>テストの実行に必要な pytest の最小バージョンを指定します</p>
<blockquote>
<div>minversion = 2.1  # pytest-2.0 で実行すると失敗する</div></blockquote>
</dd></dl>

<dl class="confval">
<dt id="confval-addopts">
<tt class="descname">addopts</tt><a class="headerlink" href="#confval-addopts" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>ユーザーが指定するようにコマンドライン引数をセットするのに特化した <tt class="docutils literal"><span class="pre">OPTS</span></tt> を追加します。次のような ini ファイルがある場合:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">pytest</span><span class="p">]</span>
<span class="n">addopts</span> <span class="o">=</span> <span class="o">--</span><span class="n">maxfail</span><span class="o">=</span><span class="mi">2</span> <span class="o">-</span><span class="n">rf</span>  <span class="c"># 2回失敗したら終了して、その内容をレポートする</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">py.test</span> <span class="pre">test_hello.py</span></tt> は、実際には次の内容と同じです:</p>
<div class="highlight-python"><pre>py.test --maxfail=2 -rf test_hello.py</pre>
</div>
<p>デフォルトでは何のオプションを追加しません。</p>
</dd></dl>

<dl class="confval">
<dt id="confval-norecursedirs">
<tt class="descname">norecursedirs</tt><a class="headerlink" href="#confval-norecursedirs" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>再帰的に探索しないテストディレクトリのディレクトリ名のパターンを設定します。それぞれ (fnmatch スタイル) のパターンがそのディレクトリ内を再帰的に調べるかを決めるのにディレクトリ名に適用されます。パターンマッチング文字は次の通りです:</p>
<div class="highlight-python"><pre>*       全てに一致する
?       任意の1文字に一致する
[seq]   seq のうち任意の1文字に一致する
[!seq]  seq のどの文字にも一致しない</pre>
</div>
<p>デフォルトパターンは <tt class="docutils literal"><span class="pre">.*</span> <span class="pre">_*</span> <span class="pre">CVS</span> <span class="pre">{args}</span></tt> となっており、 <tt class="docutils literal"><span class="pre">norecursedir</span></tt> を設定することで置き換えられます。特定のディレクトリを探索しない方法のサンプルは次の通りです:</p>
<div class="highlight-python"><pre># setup.cfg の内容
[pytest]
norecursedirs = .svn _build tmp*</pre>
</div>
<p>これは典型的な subversion と sphinx の build ディレクトリと <tt class="docutils literal"><span class="pre">tmp</span></tt> という接頭辞をもつディレクトリを再帰探索しない設定です。</p>
</dd></dl>

<dl class="confval">
<dt id="confval-python_files">
<tt class="descname">python_files</tt><a class="headerlink" href="#confval-python_files" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>python ファイルをテストモジュールとみなす、1つかそれ以上の Glob スタイルのファイルパターンです。</p>
</dd></dl>

<dl class="confval">
<dt id="confval-python_classes">
<tt class="descname">python_classes</tt><a class="headerlink" href="#confval-python_classes" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>テストクラスをテストモジュールとみなす、1つかそれ以上の接頭辞です。</p>
</dd></dl>

<dl class="confval">
<dt id="confval-python_functions">
<tt class="descname">python_functions</tt><a class="headerlink" href="#confval-python_functions" title="この定義へのパーマリンク">¶</a></dt>
<dd><p>テスト関数やメソッドをテストモジュールとみなす、1つかそれ以上の接頭辞です。</p>
<p><a class="reference internal" href="example/pythoncollection.html#change-naming-conventions"><em>命名規則の変更</em></a> のサンプルもご覧ください。</p>
</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="assert.html" title="テストのアサーションにおける書き込みとレポート"
             >次へ</a> |</li>
        <li class="right" >
          <a href="builtin.html" title="Pytest 組み込みヘルパー機能"
             >前へ</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>