Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 34af46b239e4bd529fa8060ba3c2cc13 > files > 199

python3-oslo-test-3.4.1-3.mga7.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>

    <title>OpenStack Docs: Mock autospec</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="../_static/css/bootstrap.min.css" rel="stylesheet">

<!-- Pygments CSS -->
<link href="../_static/css/native.css" rel="stylesheet">

<!-- Fonts -->
<link href="../_static/css/font-awesome.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="../_static/css/combined.css" rel="stylesheet">

<!-- Search CSS -->
<link href="../_static/css/search.css" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<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/language_data.js"></script>
  


<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-17511903-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

  </head>
  <body>

<!-- SOURCE_FILE: https://git.openstack.org/cgit/openstack/oslotest/tree/doc/source/user/mock-autospec.rst -->

 <script>
    (function (window, document) {
        var loader = function () {
            var script = document.createElement("script"), tag = document.getElementsByTagName("script")[0];
            script.src = "https://search.openstack.org/widget/embed.min.js?t="+Date.now();
            tag.parentNode.insertBefore(script, tag);
        };
        window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
    })(window, document);
</script>
<nav class="navbar navbar-default" role="navigation">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button class="navbar-toggle" data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" type="button">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <div class="brand-wrapper">
        <a class="navbar-brand" href="https://www.openstack.org/"></a>
      </div>
      <div class="search-icon show"><i class="fa fa-search"></i> Search</div></div>
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <div class="search-container tiny">
    <div class="openstack-search-bar" data-baseUrl="search.openstack.org" data-context="docs-openstack"></div>
</div>
      <ul class="nav navbar-nav navbar-main show">
        <li class="search-container-mobile">
    <div class="openstack-search-bar" data-baseUrl="search.openstack.org" data-context="docs-openstack"></div>
</li>
        <li>
          <a href="https://www.openstack.org/software/" class="drop" id="dropdownMenuSoftware">Software <i class="fa fa-caret-down"></i></a>
          <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuSoftware">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/">Overview</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/project-navigator/openstack-components">Project Navigator</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/sample-configs/">Sample Configs</a></li>
            <li role="presentation" class="divider"></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/security/">Security</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/start/">Get Started</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/roadmap/">Roadmap</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/latest-release/">Latest Release</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/software/sourcecode/">Source Code</a></li>
          </ul>
        </li>
        <li>
          <a href="https://www.openstack.org/user-stories/" class="drop" id="dropdownMenuUsers">Users <i class="fa fa-caret-down"></i></a>
          <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuUsers">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/user-stories/">Overview</a></li>
            <li role="presentation" class="divider"></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/telecoms-and-nfv/">Telecoms and NFV</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/enterprise/">OpenStack in the Enterprise</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/appdev/">Application Developers & ISVs</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="http://superuser.openstack.org/">Superuser Magazine</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/surveys/landing">User Survey</a></li>
          </ul>
        </li>
        <li>
          <a href="https://www.openstack.org/community/" class="drop" id="dropdownMenuCommunity">Community <i class="fa fa-caret-down"></i></a>
          <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuCommunity">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/community/">Welcome! Start Here</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/foundation/">OpenStack Foundation</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://wiki.openstack.org">OpenStack Wiki</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://groups.openstack.org">User Groups</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/community/speakers/">Speakers Bureau</a></li>
            <li role="presentation" class="divider"></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/foundation/companies/">Supporting Companies</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/community/jobs/">Jobs</a></li>
            <li role="presentation" class="divider"></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/join/">Join The Community</a></li>
          </ul>
        </li>
        <li>
          <a href="https://www.openstack.org/marketplace/">Marketplace</a>
        </li>
        <li>
          <a href="https://www.openstack.org/events/" class="drop" id="dropdownMenuEvents">Events <i class="fa fa-caret-down"></i></a>
          <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuEvents">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="//www.openstack.org/community/events/">Overview</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/summit/">The OpenStack Summit</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="//www.openstack.org/community/events/">More OpenStack Events</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/community/events/openstackdays">OpenStack Days</a></li>
          </ul>
        </li>
        <li>
          <a href="https://www.openstack.org/learn/" class="drop" id="dropdownMenuLearn">Learn <i class="fa fa-caret-down"></i></a>
          <ul class="dropdown-menu dropdown-hover" role="menu" aria-labelledby="dropdownMenuEvents">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/marketplace/training/">Training</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/coa/">Get Certified</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="//ask.openstack.org">Ask a Technical Question</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="//superuser.openstack.org">Superuser Magazine</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/videos/">Summit Videos</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/analysts/">Analyst Reports</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/news/">News</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/blog/">Blog</a></li>
          </ul>
        </li>
        <li>
          <a href="https://docs.openstack.org/">Docs</a>
        </li>
        <li>

</li>


            <li>

                <li class="join-nav-section">
                    <a href="https://www.openstack.org/join/" id="dropdownMenuJoin">Join <i class="fa fa-caret-down"></i></a>
                    <ul class="dropdown-menu dropdown-hover" role="menu" aria-labelledby="dropdownMenuJoin" style="display: none;">
                        <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/join/register/?membership-type=foundation">Sign up for Foundation Membership</a></li>
                        <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/join/#sponsor">Sponsor the Foundation</a></li>
                        <li role="presentation"><a role="menuitem" tabindex="-1" href="https://www.openstack.org/foundation">More about the Foundation</a></li>
                    </ul>
                </li>
                <li>
                    <a href="https://www.openstack.org/Security/login/?BackURL=/home/" class="sign-in-btn">Log In</a>
                </li>

            </li>
      </ul>
    </div>
  </div>
  <!-- /.container -->
</nav>
    <div class="container docs-book-wrapper">
      <div class="row">
        <div class="col-lg-9 col-md-8 col-sm-8 col-lg-push-3 col-md-push-4 col-sm-push-4">
<div class="row">
  <div class="col-lg-8">
      <h2>Mock autospec</h2>
    
  </div>
  <div class="docs-actions">
    
    <a href="testing.html"><i class="fa fa-angle-double-left" data-toggle="tooltip" data-placement="top" title="Previous: Testing"></i></a>
    
    
    <a href="cross-testing.html"><i class="fa fa-angle-double-right" data-toggle="tooltip" data-placement="top" title="Next: Cross-project Unit Testing"></i></a>
    
    <a id="logABugLink1" href="" target="_blank" title="Found an error? Report a bug against this page"><i class="fa fa-bug" data-toggle="tooltip" data-placement="top" title="Report a Bug"></i></a>
    
  </div>
</div>
          <div class="row docs-byline">
            <div class="docs-updated">this page last updated: 2019-01-09 17:24:56.420427</div>
          </div>
          <div class="row">
            <div class="col-lg-12">
              <div class="docs-body">

  <div class="section" id="mock-autospec">
<h1>Mock autospec<a class="headerlink" href="#mock-autospec" title="Permalink to this headline">¶</a></h1>
<p>In typical unit tests, almost all of the dependencies are mocked or patched
(<code class="docutils literal notranslate"><span class="pre">mock.patch</span></code>), without any guarantee that the mocked methods actually exist,
or if their signatures are respected. Because of this, actual issues can be
easily overlooked and missed, as the unit tests are wrongfully passing.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">mock.Mock</span></code> class accepts a spec as an argument, which only solves half
the problem: it only checks if an attribute exists, based on the given spec. It
does not guarantee that the given attribute is actually a method, or if its
signature is respected. The Mock class does not accept an autospec argument [1].</p>
<p><code class="docutils literal notranslate"><span class="pre">mock.patch</span></code>, <code class="docutils literal notranslate"><span class="pre">mock.patch.object</span></code>, <code class="docutils literal notranslate"><span class="pre">mock.patch.multiple</span></code> accept an
autospec argument, but because of a bug [2], it cannot be used properly.</p>
<p>oslotest offers a solution for problems mentioned above.</p>
<ol class="arabic simple">
<li><a class="reference external" href="https://github.com/testing-cabal/mock/issues/393">https://github.com/testing-cabal/mock/issues/393</a></li>
<li><a class="reference external" href="https://github.com/testing-cabal/mock/issues/396">https://github.com/testing-cabal/mock/issues/396</a></li>
</ol>
<div class="section" id="patching-the-mock-module">
<h2>Patching the <code class="docutils literal notranslate"><span class="pre">mock</span></code> module<a class="headerlink" href="#patching-the-mock-module" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">oslotest.mock_fixture</span></code> module contains 2 components:</p>
<ul class="simple">
<li>patch_mock_module</li>
<li>MockAutospecFixture</li>
</ul>
<p>Both components need to be used in order to fix various issues within <code class="docutils literal notranslate"><span class="pre">mock</span></code>
regarding autospec.</p>
<div class="section" id="patch-mock-module">
<h3>patch_mock_module<a class="headerlink" href="#patch-mock-module" title="Permalink to this headline">¶</a></h3>
<p>At the moment, <code class="docutils literal notranslate"><span class="pre">mock.patch</span></code>, <code class="docutils literal notranslate"><span class="pre">mock.patch.object</span></code>, <code class="docutils literal notranslate"><span class="pre">mock.patch.multiple</span></code>
accepts the <code class="docutils literal notranslate"><span class="pre">autospec</span></code> argument, but it does not correctly consume the
self / cls argument of methods or class methods.</p>
<p><code class="docutils literal notranslate"><span class="pre">patch_mock_module</span></code> addresses this issue. In order to make sure that the
original version of <code class="docutils literal notranslate"><span class="pre">mock.patch</span></code> is not used by the unit tests, this
function has to be called as early as possible within the test module, or
the base test module. E.g.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">nova</span><span class="o">/</span><span class="n">test</span><span class="o">.</span><span class="n">py</span>
<span class="o">...</span>
<span class="kn">from</span> <span class="nn">oslotest</span> <span class="k">import</span> <span class="n">mock_fixture</span>

<span class="n">mock_fixture</span><span class="o">.</span><span class="n">patch_mock_module</span><span class="p">()</span>
</pre></div>
</div>
<p>Additionally, this function will set the <code class="docutils literal notranslate"><span class="pre">autospec</span></code> argument’s value
to <code class="docutils literal notranslate"><span class="pre">True</span></code>, unless otherwise specified or these arguments are passed in:
<code class="docutils literal notranslate"><span class="pre">new_callable,</span> <span class="pre">create,</span> <span class="pre">spec</span></code>.</p>
</div>
<div class="section" id="mockautospecfixture">
<h3>MockAutospecFixture<a class="headerlink" href="#mockautospecfixture" title="Permalink to this headline">¶</a></h3>
<p><code class="docutils literal notranslate"><span class="pre">mock.Mock</span></code> and <code class="docutils literal notranslate"><span class="pre">mock.MagicMock</span></code> classes do not accept any <code class="docutils literal notranslate"><span class="pre">autospec</span></code>
argument. This fixture will replace the <code class="docutils literal notranslate"><span class="pre">mock.Mock</span></code> and <code class="docutils literal notranslate"><span class="pre">mock.MagicMock</span></code>
classes with subclasses which accepts the said argument.</p>
<p>The fixture can be used in the test <code class="docutils literal notranslate"><span class="pre">setUp</span></code> method. E.g.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">nova</span><span class="o">/</span><span class="n">test</span><span class="o">.</span><span class="n">py</span>
<span class="o">...</span>
<span class="kn">from</span> <span class="nn">oslotest</span> <span class="k">import</span> <span class="n">mock_fixture</span>

<span class="k">class</span> <span class="nc">TestCase</span><span class="p">(</span><span class="n">testtools</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">TestCase</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">setUp</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">useFixture</span><span class="p">(</span><span class="n">mock_fixture</span><span class="o">.</span><span class="n">MockAutospecFixture</span><span class="p">())</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="mock-autospec-usage">
<h2>Mock autospec usage<a class="headerlink" href="#mock-autospec-usage" title="Permalink to this headline">¶</a></h2>
<p>Consider the following class as an example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Foo</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">bar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">pass</span>
</pre></div>
</div>
<p>Using the setup described above, the following unit tests will now pass
correctly:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">FooTestCase</span><span class="p">(</span><span class="n">TestCase</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">test_mock_bar</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">mock_foo</span> <span class="o">=</span> <span class="n">mock</span><span class="o">.</span><span class="n">Mock</span><span class="p">(</span><span class="n">autospec</span><span class="o">=</span><span class="n">Foo</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertRaises</span><span class="p">(</span><span class="ne">TypeError</span><span class="p">,</span> <span class="n">mock_foo</span><span class="o">.</span><span class="n">bar</span><span class="p">,</span> <span class="n">invalid</span><span class="o">=</span><span class="s1">&#39;argument&#39;</span><span class="p">)</span>

    <span class="nd">@mock</span><span class="o">.</span><span class="n">patch</span><span class="o">.</span><span class="n">object</span><span class="p">(</span><span class="n">Foo</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">,</span> <span class="n">autospec</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">test_patch_bar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mock_bar</span><span class="p">):</span>
        <span class="n">foo</span> <span class="o">=</span> <span class="n">Foo</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertRaises</span><span class="p">(</span><span class="ne">TypeError</span><span class="p">,</span> <span class="n">foo</span><span class="o">.</span><span class="n">bar</span><span class="p">,</span> <span class="n">invalid</span><span class="o">=</span><span class="s1">&#39;argument&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>


              </div>
            </div>
          </div>
          <div class="docs-actions">
          
            <a href="testing.html"><i class="fa fa-angle-double-left" data-toggle="tooltip" data-placement="top" title="Previous: Testing"></i></a>
          
          
            <a href="cross-testing.html"><i class="fa fa-angle-double-right" data-toggle="tooltip" data-placement="top" title="Next: Cross-project Unit Testing"></i></a>
          
            <a id="logABugLink3" href="" target="_blank" title="Found an error? Report a bug against this page"><i class="fa fa-bug" data-toggle="tooltip" data-placement="top" title="Report a Bug"></i></a>
          
          </div>
          <div class="row docs-byline bottom">
            <div class="docs-updated">this page last updated: 2019-01-09 17:24:56.420427</div>
          </div>
          <div class="row">
            <div class="col-lg-8 col-md-8 col-sm-8 docs-license">
<a href="https://creativecommons.org/licenses/by/3.0/">
 <img src="../_static/images/docs/license.png" alt="Creative Commons Attribution 3.0 License"/>
</a>
<p>
 Except where otherwise noted, this document is licensed under
 <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons
 Attribution 3.0 License</a>. See all <a href="http://www.openstack.org/legal">
 OpenStack Legal Documents</a>.
</p>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-4 docs-actions-wrapper">
            <!-- ID buglinkbottom added so that pre-filled doc bugs
                 are sent to Launchpad projects related to the
                 document -->
              <a href="#" id="logABugLink2" class="docs-footer-actions"><i class="fa fa-bug"></i> found an error? report a bug</a>
              <a href="http://ask.openstack.org" class="docs-footer-actions"><i class="fa fa-question-circle"></i> questions?</a>
            </div>
          </div>
        </div>
<div class="col-lg-3 col-md-4 col-sm-4 col-lg-pull-9 col-md-pull-8 col-sm-pull-8 docs-sidebar">
  <div class="btn-group docs-sidebar-releases">
    <button onclick="location.href='/'" class="btn docs-sidebar-home" data-toggle="tooltip" data-placement="top" title="OpenStack Docs Home"><i class="fa fa-arrow-circle-o-left"></i></button>
<button href="#" type="button" data-toggle="dropdown" class="btn docs-sidebar-release-select">OpenStack Documentation<i class="fa fa-caret-down"></i></button>
    <ul class="dropdown-menu docs-sidebar-dropdown" role="menu" aria-labelledby="dLabel">
      <li role="presentation" class="dropdown-header">Guides</li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#install-guides">Install Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#user-guides">User Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#configuration-guides">Configuration Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#ops-and-admin-guides">Operations and Administration Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#api-guides">API Guides</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/index.html#contributor-guides">Contributor Guides</a></li>
      <li role="presentation" class="dropdown-header">Languages</li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/de/">Deutsch (German)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/fr/">Français (French)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/id/">Bahasa Indonesia (Indonesian)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/it/">Italiano (Italian)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/ja/">日本語 (Japanese)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/ko_KR/">한국어 (Korean)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/pt_BR/">Português (Portuguese)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/tr_TR/">Türkçe (Türkiye)</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="http://docs.openstack.org/zh_CN/">简体中文 (Simplified Chinese)</a></li>
    </ul>
  </div>
  <div class="docs-sidebar-toc">
    <div class="docs-sidebar-section" id="table-of-contents">
      <a href="../index.html" class="docs-sidebar-section-title"><h4>oslotest </h4></a>
      <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../install/index.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributor/index.html">Contributing</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Using oslotest</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="features.html">Features</a></li>
<li class="toctree-l2"><a class="reference internal" href="debugging.html">Debugging Tests</a></li>
<li class="toctree-l2"><a class="reference internal" href="testing.html">Testing</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Mock autospec</a></li>
<li class="toctree-l2"><a class="reference internal" href="cross-testing.html">Cross-project Unit Testing</a></li>
<li class="toctree-l2"><a class="reference internal" href="resources.html">Other Useful Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="history.html">CHANGES</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../reference/index.html">API</a></li>
</ul>

    </div>

  <div class="docs-sidebar-toc">
    <div class="docs-sidebar-section" id="local-table-of-contents">
      <h4 class="docs-sidebar-section-title">Page Contents</h4>
      <ul>
<li><a class="reference internal" href="#">Mock autospec</a><ul>
<li><a class="reference internal" href="#patching-the-mock-module">Patching the <code class="docutils literal notranslate"><span class="pre">mock</span></code> module</a><ul>
<li><a class="reference internal" href="#patch-mock-module">patch_mock_module</a></li>
<li><a class="reference internal" href="#mockautospecfixture">MockAutospecFixture</a></li>
</ul>
</li>
<li><a class="reference internal" href="#mock-autospec-usage">Mock autospec usage</a></li>
</ul>
</li>
</ul>

    </div>
  </div>
  </div>
</div>
      </div>
    </div>
<footer>
  <div class="container">
    <div class="row footer-links">
      <div class="col-lg-2 col-sm-2">
        <h3>OpenStack</h3>
        <ul>
          <li><a href="http://openstack.org/projects/">Projects</a></li>
          <li><a href="http://openstack.org/projects/openstack-security/">OpenStack Security</a></li>
          <li><a href="http://openstack.org/projects/openstack-faq/">Common Questions</a></li>
          <li><a href="http://openstack.org/blog/">Blog</a></li>
          <li><a href="http://openstack.org/news/">News</a></li>
        </ul>
      </div>
      <div class="col-lg-2 col-sm-2">
        <h3>Community</h3>
        <ul>
          <li><a href="http://openstack.org/community/">User Groups</a></li>
          <li><a href="http://openstack.org/community/events/">Events</a></li>
          <li><a href="http://openstack.org/community/jobs/">Jobs</a></li>
          <li><a href="http://openstack.org/foundation/companies/">Companies</a></li>
          <li><a href="http://docs.openstack.org/infra/manual/developers.html">Contribute</a></li>
        </ul>
      </div>
      <div class="col-lg-2 col-sm-2">
        <h3>Documentation</h3>
        <ul>
          <li><a href="http://docs.openstack.org">OpenStack Manuals</a></li>
          <li><a href="http://openstack.org/software/start/">Getting Started</a></li>
          <li><a href="http://developer.openstack.org">API Documentation</a></li>
          <li><a href="https://wiki.openstack.org">Wiki</a></li>
        </ul>
      </div>
      <div class="col-lg-2 col-sm-2">
        <h3>Branding & Legal</h3>
        <ul>
          <li><a href="http://openstack.org/brand/">Logos & Guidelines</a></li>
          <li><a href="http://openstack.org/brand/openstack-trademark-policy/">Trademark Policy</a></li>
          <li><a href="http://openstack.org/privacy/">Privacy Policy</a></li>
          <li><a href="https://wiki.openstack.org/wiki/How_To_Contribute#Contributor_License_Agreement">OpenStack CLA</a></li>
        </ul>
      </div>
      <div class="col-lg-4 col-sm-4">
        <h3>Stay In Touch</h3>
        <a href="https://twitter.com/OpenStack" target="_blank" class="social-icons footer-twitter"></a>
        <a href="https://www.facebook.com/openstack" target="_blank" class="social-icons footer-facebook"></a>
        <a href="https://www.linkedin.com/company/openstack" target="_blank" class="social-icons footer-linkedin"></a>
        <a href="https://www.youtube.com/user/OpenStackFoundation" target="_blank" class="social-icons footer-youtube"></a>
        <p class="fine-print">
          The OpenStack project is provided under the
          <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0 license</a>. Openstack.org is powered by
          <a href="http://rackspace.com" target="_blank">Rackspace Cloud Computing</a>.
        </p>
      </div>
    </div>
  </div>
</footer>
<!-- jQuery -->
<script type="text/javascript" src="../_static/js/jquery-3.2.1.min.js"></script>

<!-- Bootstrap JavaScript -->
<script type="text/javascript" src="../_static/js/bootstrap.min.js"></script>

<!-- The rest of the JS -->
<script type="text/javascript" src="../_static/js/navigation.js"></script>

<!-- Docs JS -->
<script type="text/javascript" src="../_static/js/docs.js"></script>

<!-- Popovers -->
<script type="text/javascript" src="../_static/js/webui-popover.js"></script>

<!-- standard sphinx include libraries, which allow search highlighting -->
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/searchtools.js"></script>

<script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        SOURCELINK_SUFFIX: '.txt',
        HAS_SOURCE:  true
      };
</script>


<!-- Javascript for page -->
<script language="JavaScript">
/* build a description of this page including SHA, source location on git repo,
   build time and the project's launchpad bug tag. Set the HREF of the bug
   buttons */

    var lineFeed = "%0A";
    var gitURL = "Source: Can't derive source file URL";

    /* there have been cases where "pagename" wasn't set; better check for it */
        /* "giturl" is the URL of the source file on Git and is auto-generated by
           openstackdocstheme.

           "pagename" is a standard sphinx parameter containing the name of
           the source file, without extension.                             */

        var sourceFile = "user/mock-autospec" + ".rst";
        gitURL = "Source: https://git.openstack.org/cgit/openstack/oslotest/tree/doc/source" + "/" + sourceFile;

    /* gitsha, project and bug_tag rely on variables in conf.py */
    var gitSha = "SHA: unknown";
    var repositoryName = "openstack/oslotest";
        var bugProject = "oslotest";
        var bugTitle = "Mock autospec in oslotest";
    var fieldTags = "";
        var useStoryboard = "";


    /* "last_updated" is the build date and time. It relies on the
       conf.py variable "html_last_updated_fmt", which should include
       year/month/day as well as hours and minutes                   */
    var buildstring = "Release:  on 2019-01-09 17:24:56.420427";

    var fieldComment = encodeURI(buildstring) +
                       lineFeed + encodeURI(gitSha) +
                       lineFeed + encodeURI(gitURL) ;

    logABug(bugTitle, bugProject, fieldComment, fieldTags, repositoryName, useStoryboard);
</script>


  </body>
</html>