<!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 API and builtin fixtures</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.3.4.1', 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> <link rel="top" title="None" href="index.html" /> <link rel="up" title="py.test reference documentation" href="apiref.html" /> <link rel="next" title="Basic test configuration" href="customize.html" /> <link rel="prev" title="py.test reference documentation" href="apiref.html" /> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="customize.html" title="Basic test configuration" accesskey="N">next</a></li> <li class="right" > <a href="apiref.html" title="py.test reference documentation" accesskey="P">previous</a> |</li> <li><a href="contents.html">pytest-2.3.4.1</a> »</li> <li><a href="apiref.html" accesskey="U">py.test reference documentation</a> »</li> <g:plusone></g:plusone> </ul> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <div id="searchbox" style="display: none"> <form class="search" action="search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Search" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('#searchbox').show(0);</script> <h3>quicklinks</h3> <div style="text-align: left; font-size: 100%; vertical-align: middle;"> <table> <tr> <td> <a href="index.html">home</a> </td><td> <a href="contents.html">TOC/contents</a> </td></tr><tr><td> <a href="getting-started.html">install</a> </td><td> <a href="changelog.html">changelog</a> </td></tr><tr><td> <a href="example/index.html">examples</a> </td><td> <a href="customize.html">customize</a> </td></tr><tr><td> <a href="https://bitbucket.org/hpk42/pytest/issues?status=new&status=open">issues[bb]</a> </td><td> <a href="contact.html">contact</a> </td></tr></table> </div> <h3><a href="contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Pytest API and builtin fixtures</a><ul> <li><a class="reference internal" href="#invoking-pytest-interactively">Invoking pytest interactively</a></li> <li><a class="reference internal" href="#helpers-for-assertions-about-exceptions-warnings">Helpers for assertions about Exceptions/Warnings</a></li> <li><a class="reference internal" href="#raising-a-specific-test-outcome">Raising a specific test outcome</a></li> <li><a class="reference internal" href="#fixtures-and-requests">fixtures and requests</a></li> <li><a class="reference internal" href="#builtin-fixtures-function-arguments">Builtin fixtures/function arguments</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="apiref.html" title="previous chapter">py.test reference documentation</a></p> <h4>Next topic</h4> <p class="topless"><a href="customize.html" title="next chapter">Basic test configuration</a></p> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="pytest-api-and-builtin-fixtures"> <span id="pytest-helpers"></span><h1>Pytest API and builtin fixtures<a class="headerlink" href="#pytest-api-and-builtin-fixtures" title="Permalink to this headline">¶</a></h1> <p>This is a list of <tt class="docutils literal"><span class="pre">pytest.*</span></tt> API functions and fixtures.</p> <p>For information on plugin hooks and objects, see <a class="reference internal" href="plugins.html#plugins"><em>Working with plugins and conftest files</em></a>.</p> <p>For information on the <tt class="docutils literal"><span class="pre">pytest.mark</span></tt> mechanism, see <a class="reference internal" href="mark.html#mark"><em>Marking test functions with attributes</em></a>.</p> <p>For the below objects, you can also interactively ask for help, e.g. by typing on the Python interactive prompt something like:</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> <div class="section" id="invoking-pytest-interactively"> <h2>Invoking pytest interactively<a class="headerlink" href="#invoking-pytest-interactively" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="pytest.main"> <tt class="descname">main</tt><big>(</big><em>args=None</em>, <em>plugins=None</em><big>)</big><a class="headerlink" href="#pytest.main" title="Permalink to this definition">¶</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">Parameters:</th><td class="field-body"><ul class="first last simple"> <li><strong>args</strong> – list of command line arguments.</li> <li><strong>plugins</strong> – list of plugin objects to be auto-registered during initialization.</li> </ul> </td> </tr> </tbody> </table> </dd></dl> <p>More examples at <a class="reference internal" href="usage.html#pytest-main-usage"><em>Calling pytest from Python code</em></a></p> </div> <div class="section" id="helpers-for-assertions-about-exceptions-warnings"> <h2>Helpers for assertions about Exceptions/Warnings<a class="headerlink" href="#helpers-for-assertions-about-exceptions-warnings" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="pytest.raises"> <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="Permalink to this definition">¶</a></dt> <dd><p>assert that a code block/function call raises @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">>>> </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">>>> </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"><ExceptionInfo ...></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">>>> </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">>>> </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"><ExceptionInfo ...></span> <span class="gp">>>> </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"><ExceptionInfo ...></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">>>> </span><span class="n">raises</span><span class="p">(</span><span class="ne">ZeroDivisionError</span><span class="p">,</span> <span class="s">"f(0)"</span><span class="p">)</span> <span class="go"><ExceptionInfo ...></span> </pre></div> </div> </dd></dl> <p>Examples at <a class="reference internal" href="assert.html#assertraises"><em>Assertions about expected exceptions</em></a>.</p> <dl class="function"> <dt id="pytest.deprecated_call"> <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="Permalink to this definition">¶</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="raising-a-specific-test-outcome"> <h2>Raising a specific test outcome<a class="headerlink" href="#raising-a-specific-test-outcome" title="Permalink to this headline">¶</a></h2> <p>You can use the following functions in your test, fixture or setup functions to force a certain test outcome. Note that most often you can rather use declarative marks, see <a class="reference internal" href="skipping.html#skipping"><em>Skip and xfail: dealing with tests that can not succeed</em></a>.</p> <dl class="function"> <dt id="_pytest.runner.fail"> <tt class="descname">fail</tt><big>(</big><em>msg=''</em>, <em>pytrace=True</em><big>)</big><a class="reference internal" href="_modules/_pytest/runner.html#fail"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.runner.fail" title="Permalink to this definition">¶</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">Parameters:</th><td class="field-body"><strong>pytrace</strong> – 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.runner.skip"> <tt class="descname">skip</tt><big>(</big><em>msg=''</em><big>)</big><a class="reference internal" href="_modules/_pytest/runner.html#skip"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.runner.skip" title="Permalink to this definition">¶</a></dt> <dd><p>skip an executing test with the given message. Note: it’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.runner.importorskip"> <tt class="descname">importorskip</tt><big>(</big><em>modname</em>, <em>minversion=None</em><big>)</big><a class="reference internal" href="_modules/_pytest/runner.html#importorskip"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.runner.importorskip" title="Permalink to this definition">¶</a></dt> <dd><p>return imported module if it has a higher __version__ than the optionally specified ‘minversion’ - otherwise call py.test.skip() with a message detailing the mismatch.</p> </dd></dl> <dl class="function"> <dt id="_pytest.skipping.xfail"> <tt class="descname">xfail</tt><big>(</big><em>reason=''</em><big>)</big><a class="reference internal" href="_modules/_pytest/skipping.html#xfail"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.skipping.xfail" title="Permalink to this definition">¶</a></dt> <dd><p>xfail an executing test or setup functions with the given reason.</p> </dd></dl> <dl class="function"> <dt id="_pytest.runner.exit"> <tt class="descname">exit</tt><big>(</big><em>msg</em><big>)</big><a class="reference internal" href="_modules/_pytest/runner.html#exit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.runner.exit" title="Permalink to this definition">¶</a></dt> <dd><p>exit testing process as if KeyboardInterrupt was triggered.</p> </dd></dl> </div> <div class="section" id="fixtures-and-requests"> <h2>fixtures and requests<a class="headerlink" href="#fixtures-and-requests" title="Permalink to this headline">¶</a></h2> <p>To mark a fixture function:</p> <dl class="function"> <dt id="_pytest.python.fixture"> <tt class="descname">fixture</tt><big>(</big><em>scope='function'</em>, <em>params=None</em>, <em>autouse=False</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#fixture"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.python.fixture" title="Permalink to this definition">¶</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">Parameters:</th><td class="field-body"><ul class="first last simple"> <li><strong>scope</strong> – the scope for which this fixture is shared, one of “function” (default), “class”, “module”, “session”.</li> <li><strong>params</strong> – 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> – 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> <p>Tutorial at <a class="reference internal" href="fixture.html#fixtures"><em>pytest fixtures: explicit, modular, scalable</em></a>.</p> <p>The <tt class="docutils literal"><span class="pre">request</span></tt> object that can be used from fixture functions.</p> <dl class="class"> <dt id="_pytest.python.FixtureRequest"> <em class="property">class </em><tt class="descname">FixtureRequest</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest" title="Permalink to this definition">¶</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.fixturename"> <tt class="descname">fixturename</tt><em class="property"> = None</em><a class="headerlink" href="#_pytest.python.FixtureRequest.fixturename" title="Permalink to this definition">¶</a></dt> <dd><p>fixture for which this request is being performed</p> </dd></dl> <dl class="attribute"> <dt id="_pytest.python.FixtureRequest.scope"> <tt class="descname">scope</tt><em class="property"> = None</em><a class="headerlink" href="#_pytest.python.FixtureRequest.scope" title="Permalink to this definition">¶</a></dt> <dd><p>Scope string, one of “function”, “cls”, “module”, “session”</p> </dd></dl> <dl class="attribute"> <dt id="_pytest.python.FixtureRequest.node"> <tt class="descname">node</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.node"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.node" title="Permalink to this definition">¶</a></dt> <dd><p>underlying collection node (depends on current request scope)</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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.config" title="Permalink to this definition">¶</a></dt> <dd><p>the pytest config object associated with this request.</p> </dd></dl> <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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.function" title="Permalink to this definition">¶</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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.cls" title="Permalink to this definition">¶</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.instance"> <tt class="descname">instance</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.instance"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.instance" title="Permalink to this definition">¶</a></dt> <dd><p>instance (can be None) on which 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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.module" title="Permalink to this definition">¶</a></dt> <dd><p>python module object where the test function was collected.</p> </dd></dl> <dl class="attribute"> <dt id="_pytest.python.FixtureRequest.fspath"> <tt class="descname">fspath</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.fspath"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.fspath" title="Permalink to this definition">¶</a></dt> <dd><p>the file system path of the test module which collected this test.</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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.keywords" title="Permalink to this definition">¶</a></dt> <dd><p>keywords/markers dictionary for the underlying node.</p> </dd></dl> <dl class="attribute"> <dt id="_pytest.python.FixtureRequest.session"> <tt class="descname">session</tt><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.session"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.session" title="Permalink to this definition">¶</a></dt> <dd><p>pytest session object.</p> </dd></dl> <dl class="method"> <dt id="_pytest.python.FixtureRequest.addfinalizer"> <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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.addfinalizer" title="Permalink to this definition">¶</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.applymarker"> <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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.applymarker" title="Permalink to this definition">¶</a></dt> <dd><p>Apply a marker to a single test function invocation. This method is useful if you don’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">Parameters:</th><td class="field-body"><strong>marker</strong> – 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.raiseerror"> <tt class="descname">raiseerror</tt><big>(</big><em>msg</em><big>)</big><a class="reference internal" href="_modules/_pytest/python.html#FixtureRequest.raiseerror"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.raiseerror" title="Permalink to this definition">¶</a></dt> <dd><p>raise a FixtureLookupError with the given message.</p> </dd></dl> <dl class="method"> <dt id="_pytest.python.FixtureRequest.cached_setup"> <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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.cached_setup" title="Permalink to this definition">¶</a></dt> <dd><p>(deprecated) Return a testing resource managed by <tt class="docutils literal"><span class="pre">setup</span></tt> & <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">Parameters:</th><td class="field-body"><ul class="first last simple"> <li><strong>teardown</strong> – function receiving a previously setup resource.</li> <li><strong>setup</strong> – a no-argument function creating a resource.</li> <li><strong>scope</strong> – 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> – added to internal caching key of (funcargname, scope).</li> </ul> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="_pytest.python.FixtureRequest.getfuncargvalue"> <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">[source]</span></a><a class="headerlink" href="#_pytest.python.FixtureRequest.getfuncargvalue" title="Permalink to this definition">¶</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> </dd></dl> </div> <div class="section" id="builtin-fixtures-function-arguments"> <span id="builtinfuncargs"></span><span id="builtinfixtures"></span><h2>Builtin fixtures/function arguments<a class="headerlink" href="#builtin-fixtures-function-arguments" title="Permalink to this headline">¶</a></h2> <p>You can ask for available builtin or project-custom <a class="reference internal" href="fixture.html#fixtures"><em>fixtures</em></a> by typing:</p> <div class="highlight-python"><pre>$ py.test -q --fixtures capsys enables capturing of writes to sys.stdout/sys.stderr and makes captured output available via ``capsys.readouterr()`` method calls which return a ``(out, err)`` tuple. capfd enables capturing of writes to file descriptors 1 and 2 and makes captured output available via ``capsys.readouterr()`` method calls which return a ``(out, err)`` tuple. monkeypatch The returned ``monkeypatch`` funcarg provides these helper methods to modify objects, dictionaries or os.environ:: monkeypatch.setattr(obj, name, value, raising=True) monkeypatch.delattr(obj, name, raising=True) monkeypatch.setitem(mapping, name, value) monkeypatch.delitem(obj, name, raising=True) monkeypatch.setenv(name, value, prepend=False) monkeypatch.delenv(name, value, raising=True) monkeypatch.syspath_prepend(path) monkeypatch.chdir(path) All modifications will be undone after the requesting test function has finished. The ``raising`` parameter determines if a KeyError or AttributeError will be raised if the set/deletion operation has no target. pytestconfig the pytest config object with access to command line opts. recwarn Return a WarningsRecorder instance that provides these methods: * ``pop(category=None)``: return last warning matching the category. * ``clear()``: clear list of warnings See http://docs.python.org/library/warnings.html for information on warning categories. tmpdir return a temporary directory path object which is unique to each test function invocation, created as a sub directory of the base temporary directory. The returned object is a `py.path.local`_ path object.</pre> </div> </div> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="customize.html" title="Basic test configuration" >next</a></li> <li class="right" > <a href="apiref.html" title="py.test reference documentation" >previous</a> |</li> <li><a href="contents.html">pytest-2.3.4.1</a> »</li> <li><a href="apiref.html" >py.test reference documentation</a> »</li> <g:plusone></g:plusone> </ul> </div> <div class="footer"> © Copyright 2012, holger krekel. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-7597274-13']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> </body> </html>