<div dir="ltr">Cheers Ned ;-)<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 14 August 2014 15:04, Ned Batchelder <span dir="ltr">&lt;<a href="mailto:ned@nedbatchelder.com" target="_blank">ned@nedbatchelder.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    &quot;I guess you&#39;re not a django user&quot;!!  Harry is the author of
    Test-Driven Development with Python
    (<a href="http://www.obeythetestinggoat.com/" target="_blank">http://www.obeythetestinggoat.com/</a>) which features Django....<span class="HOEnZb"><font color="#888888"><br>
    <br>
    --Ned.</font></span><div><div class="h5"><br>
    <br>
    <div>On 8/14/14 9:09 AM, Marcin Tustin
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      
      
      <div>
        <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">I
            guess you’re not a django user – that would cut against the
            grain of the design of class based views. Inheritance IS the
            composition mechanism, and it works well, but it leads to
            this particular challenge with testing. In fact, I’m very
            satisfied with mocking super as a solution; it will only be
            in a minority of cases that anything more sophisticated is
            required.
            <u></u><u></u></span></p>
        <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></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;">
            <a href="mailto:testing-in-python-bounces@lists.idyll.org" target="_blank">testing-in-python-bounces@lists.idyll.org</a>
            [<a href="mailto:testing-in-python-bounces@lists.idyll.org" target="_blank">mailto:testing-in-python-bounces@lists.idyll.org</a>]
            <b>On Behalf Of </b>Harry Percival<br>
            <b>Sent:</b> Thursday, August 14, 2014 8:51 AM<br>
            <b>Cc:</b> <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
            <b>Subject:</b> Re: [TIP] Unit testing functions which call
            super<u></u><u></u></span></p>
        <p class="MsoNormal"><u></u> <u></u></p>
        <div>
          <p class="MsoNormal">Any mileage in doing the &quot;prefer
            composition over inheritance&quot; thing?<u></u><u></u></p>
          <div>
            <p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
            <div>
              <p class="MsoNormal">On 14 August 2014 13:31, Marcin
                Tustin &lt;<a href="mailto:Marcin.Tustin@dealertrack.com" target="_blank">Marcin.Tustin@dealertrack.com</a>&gt;
                wrote:<u></u><u></u></p>
              <div>
                <div>
                  <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">I
                      can’t share real code, but what I can tell you is
                      that it’s django code – we’ve got a lot multiple
                      inheritance going on with class based views. None
                      of these methods are going to stop having super
                      calls (or if they do, that will very much be the
                      exception).
                    </span><u></u><u></u></p>
                  <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span><u></u><u></u></p>
                  <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">As
                      to behaviour-driven testing: I usually use that,
                      and minimize mocks. With class based views, each
                      class implements a different behaviour, and the
                      inheritance hierarchy is fairly deep (at least
                      three classes). Accordingly, each method really
                      does need to be tested independently, because it
                      is not that the method uses super to implement one
                      behaviour; rather it is triggering the next
                      behaviour, whatever that may be. </span><u></u><u></u></p>
                  <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> </span><u></u><u></u></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 [mailto:<a href="mailto:dstanek@dstanek.com" target="_blank">dstanek@dstanek.com</a>]
                      <br>
                      <b>Sent:</b> Wednesday, August 13, 2014 7:13 PM<br>
                      <b>To:</b> Marcin Tustin<br>
                      <b>Cc:</b> Ned Batchelder; <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">
                        testing-in-python@lists.idyll.org</a></span><u></u><u></u></p>
                  <div>
                    <p class="MsoNormal"><br>
                      <b>Subject:</b> Re: [TIP] Unit testing functions
                      which call super<u></u><u></u></p>
                  </div>
                  <p class="MsoNormal"> <u></u><u></u></p>
                  <div>
                    <div>
                      <p class="MsoNormal"> <u></u><u></u></p>
                      <div>
                        <p class="MsoNormal">On
                          Wed, Aug 13, 2014 at 6:54 PM, Marcin Tustin
                          &lt;<a href="mailto:Marcin.Tustin@dealertrack.com" target="_blank">Marcin.Tustin@dealertrack.com</a>&gt;
                          wrote:<u></u><u></u></p>
                        <div>
                          <div>
                            <div>
                              <div>
                                <p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">It’s
                                    not  question of terminology. What
                                    happens if I let the test call it’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’t be defined
                                    by this code, but some other code,
                                    so I can’t usefully test anything
                                    about it other than its type. If it
                                    doesn’t work, then I have to deal
                                    with those exceptions, but then I
                                    can’t very well distinguish between
                                    exceptions originating in the code
                                    I’m testing, and exceptions in the
                                    super methods. It’s all the usual
                                    reasons for mocking out calls.</span><u></u><u></u></p>
                              </div>
                            </div>
                            <p class="MsoNormal"> <u></u><u></u></p>
                          </div>
                        </div>
                      </div>
                      <div>
                        <div>
                          <div>
                            <p class="MsoNormal"> <u></u><u></u></p>
                          </div>
                          <p class="MsoNormal">I
                            think about my tests differently. I don&#39;t
                            care how the feature is implemented all I
                            care about is if it works. Mocking super
                            means that you can&#39;t refactor your code
                            without changing tests.<u></u><u></u></p>
                        </div>
                      </div>
                    </div>
                    <div>
                      <div>
                        <div>
                          <p class="MsoNormal"> <u></u><u></u></p>
                        </div>
                        <div>
                          <p class="MsoNormal">Do
                            you have any real code to share?  I suspect
                            that the method you had in your original
                            post isn&#39;t real production code.  But if I
                            just look at that example the only thing I
                            would mock is `do_some_stuff` because it&#39;s a
                            collaborator.<br clear="all">
                            <u></u><u></u></p>
                          <div>
                            <p class="MsoNormal"> <u></u><u></u></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><u></u><u></u></p>
                          <div>
                            <p class="MsoNormal">www:
                              <a href="http://dstanek.com" target="_blank">http://dstanek.com</a><u></u><u></u></p>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <p class="MsoNormal" style="margin-bottom:12.0pt"><br>
                _______________________________________________<br>
                testing-in-python mailing list<br>
                <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
                <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><u></u><u></u></p>
            </div>
            <p class="MsoNormal"><br>
              <br clear="all">
              <br>
              -- <br>
              ------------------------------<br>
              Harry J.W. Percival<br>
              ------------------------------<br>
              Twitter: @hjwp<br>
              Mobile:  +44 (0) 78877 02511<br>
              Skype:         harry.percival <u></u><u></u></p>
          </div>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>_______________________________________________
testing-in-python mailing list
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a>
</pre>
    </blockquote>
    <br>
  </div></div></div>

<br>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>------------------------------<br>Harry J.W. Percival<br>------------------------------<br>Twitter: @hjwp<br>Mobile:  +44 (0) 78877 02511<br>Skype:         harry.percival
</div>