<div dir="ltr">Wrongly sent to Joshua only, hence fwding to the list.<br><div><br><div class="gmail_quote">--------------<br><br><div dir="ltr"><div>Joshua,<br></div> If my code has logs warning, error, debug based on diff exceptions or conditions, its good to test them & have a unit test around it<br>
so that we can catch scenarios where we modified code that ideally shud have just put a warn but wrongly put a debug/error. Thats my only intention here<br>
</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 3, 2014 at 11:54 PM, Joshua Harlow <span dir="ltr"><<a href="mailto:harlowja@yahoo-inc.com" target="_blank">harlowja@yahoo-inc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif">
<div>Why is mocking the LOG object useful/being used?</div>
<div><br>
</div>
<div>Testing functionality which depends on LOG triggers/calls imho is bad practice (and usually means something needs to be refactored).</div>
<div><br>
</div>
<div>LOG statements, and calls should be expected to move/be removed <i>often</i> so testing functionality in tests with them seems like the wrong approach.</div>
<div><br>
</div>
<div>My 2 cents.</div>
<div><br>
</div>
<span>
<div style="font-family:Calibri;font-size:11pt;text-align:left;color:black;BORDER-BOTTOM:medium none;BORDER-LEFT:medium none;PADDING-BOTTOM:0in;PADDING-LEFT:0in;PADDING-RIGHT:0in;BORDER-TOP:#b5c4df 1pt solid;BORDER-RIGHT:medium none;PADDING-TOP:3pt">
<span style="font-weight:bold">From: </span>Deepak Shetty <<a href="mailto:dpkshetty@gmail.com" target="_blank">dpkshetty@gmail.com</a>><br>
<span style="font-weight:bold">Reply-To: </span>"OpenStack Development Mailing List (not for usage questions)" <<a href="mailto:openstack-dev@lists.openstack.org" target="_blank">openstack-dev@lists.openstack.org</a>><br>
<span style="font-weight:bold">Date: </span>Tuesday, June 3, 2014 at 9:16 AM<br>
<span style="font-weight:bold">To: </span>"OpenStack Development Mailing List (not for usage questions)" <<a href="mailto:openstack-dev@lists.openstack.org" target="_blank">openstack-dev@lists.openstack.org</a>><br>
<span style="font-weight:bold">Subject: </span>[openstack-dev] [Cinder] How to mock the LOG inside cinder driver<br>
</div><div><div>
<div><br>
</div>
<blockquote style="BORDER-LEFT:#b5c4df 5 solid;PADDING:0 0 0 5;MARGIN:0 0 0 5">
<div>
<div>
<div dir="ltr">
<div>
<div>
<div>
<div>
<div><deepakcs> Hi, whats the right way to mock the LOG variable inside the driver ? I am mocking mock.patch.object(glusterfs, 'LOG') as mock_logger<br>
<deepakcs> and then doing...<br>
<deepakcs> mock_logger.warning.assert_called_once() - which passes and is expected to pass per my code<br>
<deepakcs> but<br>
<deepakcs> mock_logger.debug.assert_called_once() - shud fail , but this also passes !<br>
<deepakcs> any idea why ?<br>
<br>
</div>
I feel that I am not mocking the LOG inside the driver correctly.<br>
<br>
I also tried<br>
mock.patch.object(glusterfs.LOG, 'warning'),<br>
mock.patch.object(glusterfs.LOG, 'debug')<br>
</div>
as mock_logger_warn and mock_logger_debug respectively<br>
<br>
</div>
But here too<br>
</div>
.debug and .warning both passes.. while the expected result is for .warning to pass and .debug to fail<br>
<br>
</div>
So somehow I am unable to mock LOG properly<br>
<br>
thanx,<br>
deepak<br>
</div>
</div>
</div>
</blockquote>
</div></div></span>
</div>
</blockquote></div><br></div>
</div></div></div><br></div></div>