<div dir="ltr"><div><div><div><div><div><br></div>Hi all,<br><br></div>I announced this originally a few years ago on this list when it had just been launched as a separate project. A lot of effort has since gone into it and it&#39;s been used in a few more contexts since then so I&#39;ve decided to announce that the current release is 1.0 and that it is now a stable product.<br>
<br></div>This is not Yet Another Python Mocking Tool. Its primary aim is to support functional/acceptance testing rather than unit testing, and to for example mock out interactions with entire subsystems and third-party modules, as well as individual method calls.<br>
<br></div><div>A major aim is to make it easier to keep mocks in synch with the real system behaviour, indeed to be able to generate them from it. This both saves effort and provides insurance against the common problem where mock code and real code gradually diverge.<br>
<br></div>The approach is therefore to generate mocks by recording interaction with the real system, and to then be able to use them in replay mode. So there are two &quot;modes&quot; to run every test. *Note* that this is genuine record-replay like GUI-test tools have, not the kind available in e.g. Mocker or Easymock. <br>
<br></div>Using it in your tests is very simple. For example:<br><div><br>from <span class="">capturemock</span> import <span class="">capturemock</span><br>
<br>
@<span class="">capturemock</span>(&quot;smtplib&quot;)<br>
def test_something_sending_email():<br>
     # etc<br>
<br>
@<span class="">capturemock</span>(&quot;datetime.datetime.now&quot;)<br>
def test_some_real_time_code():<br>
     # etc<br>
<br>
@<span class="">capturemock</span>(&quot;matplotlib&quot;)<br>
def test_my_graph_stuff():<br>
     # etc<br></div><div><br></div><div>You can then set the environment variable CAPTUREMOCK_MODE to determine whether it will use pre-existing mocks to replay from, or regenerate them from real behaviour.<br></div><div>
<br></div><div>For more details please see the website at<br><a href="http://texttest.org/index.php?page=capturemock">http://texttest.org/index.php?page=capturemock</a><br></div><div><br>Marc Abramowitz has also put up some more realistic examples at<br>
<a href="https://github.com/msabramo/capturemock_examples">https://github.com/msabramo/capturemock_examples</a><br><br></div><div>Regards,<br>Geoff Bache<br><br></div></div>