<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        color:black;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";
        color:black;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">It&#8217;s not&nbsp; question of terminology. What happens if I let the test call it&#8217;s super is impossible to anticipate (but in practice will be some kind of exception).
 Even if it successfully calls the super methods, the output won&#8217;t be defined by this code, but some other code, so I can&#8217;t usefully test anything about it other than its type. If it doesn&#8217;t work, then I have to deal with those exceptions, but then I can&#8217;t
 very well distinguish between exceptions originating in the code I&#8217;m testing, and exceptions in the super methods. It&#8217;s all the usual reasons for mocking out calls.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:windowtext">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:windowtext"> testing-in-python-bounces@lists.idyll.org [mailto:testing-in-python-bounces@lists.idyll.org]
<b>On Behalf Of </b>Ned Batchelder<br>
<b>Sent:</b> Wednesday, August 13, 2014 5:13 PM<br>
<b>To:</b> testing-in-python@lists.idyll.org<br>
<b>Subject:</b> Re: [TIP] Unit testing functions which call super<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">On 8/13/14 4:15 PM, Marcin Tustin wrote:<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Yes: the reason is that I&#8217;m not writing an integration test, I&#8217;m writing a test to test this specific method. We need unit tests to test our individual units,
 and integration tests to test them together. It&#8217;s not wise to rely only on integration tests (nor only on unit tests).</span><o:p></o:p></p>
<p class="MsoNormal"><br>
I say let the test call super(), and call it a unit test.&nbsp; These terms can't be taken too literally.&nbsp; Other than it being &quot;the wrong kind&quot; of test, what actual bad thing will happen if you call super() in your unit test?<br>
<br>
This seems like a lot of effort to subvert Python's class machinery.&nbsp; You'll end up with a mess, and probably more follow-on problems than you solve.<br>
<br>
Probably the best approach is to refactor your code so that its more easily tested: if you are interested in what foofunc does without consideration of the base class, then create a function that doesn't call the base class.&nbsp; Test that function.&nbsp; Then you can
 call that function from another which does call the base class.<br>
<br>
--Ned.<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">I actually do share the concern about over mocking (it&#8217;s easy to mock so much that you test nothing), but it&#8217;s important not to throw the baby out with the
 bathwater. Integration tests by their nature lack granularity to pinpoint problems (and yes, I realize it&#8217;s possible and desirable to set up integration tests so that do point to where a detected problem originates, but it&#8217;s still not a substitute for appropriate
 unit testing).</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> David Stanek [<a href="mailto:dstanek@dstanek.com">mailto:dstanek@dstanek.com</a>]
<br>
<b>Sent:</b> Wednesday, August 13, 2014 2:35 PM<br>
<b>To:</b> Marcin Tustin<br>
<b>Cc:</b> <a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<b>Subject:</b> Re: [TIP] Unit testing functions which call super</span><o:p></o:p></p>
<p class="MsoNormal">&nbsp;<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">&nbsp;<o:p></o:p></p>
<div>
<p class="MsoNormal">On Wed, Aug 13, 2014 at 2:00 PM, Marcin Tustin &lt;<a href="mailto:Marcin.Tustin@dealertrack.com" target="_blank">Marcin.Tustin@dealertrack.com</a>&gt; wrote:<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hi All,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I&#8217;ve come across a method which I needed to add a unit test for, which calls super, e.g.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"><br>
Is there any reason you can't call the parent's super? &nbsp;In my view of testing you want to create an object, feed it input, and then check the output/side effect. I would stay away from mocking internals like this.<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal">&nbsp;<o:p></o:p></p>
</div>
<p class="MsoNormal">-- <br>
David<br>
blog: <a href="http://www.traceback.org" target="_blank">http://www.traceback.org</a><br>
twitter: <a href="http://twitter.com/dstanek" target="_blank">http://twitter.com/dstanek</a><o:p></o:p></p>
<div>
<p class="MsoNormal">www: <a href="http://dstanek.com" target="_blank">http://dstanek.com</a><o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>testing-in-python mailing list<o:p></o:p></pre>
<pre><a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><o:p></o:p></pre>
<pre><a href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a><o:p></o:p></pre>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>