[openstack-dev] Fwd: [Cinder] How to mock the LOG inside cinder driver

Deepak Shetty dpkshetty at gmail.com
Wed Jun 4 05:20:08 UTC 2014


Wrongly sent to Joshua only, hence fwding to the list.

--------------

Joshua,
  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
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


On Tue, Jun 3, 2014 at 11:54 PM, Joshua Harlow <harlowja at yahoo-inc.com>
wrote:

>  Why is mocking the LOG object useful/being used?
>
>  Testing functionality which depends on LOG triggers/calls imho is bad
> practice (and usually means something needs to be refactored).
>
>  LOG statements, and calls should be expected to move/be removed *often*
> so testing functionality in tests with them seems like the wrong approach.
>
>  My 2 cents.
>
>   From: Deepak Shetty <dpkshetty at gmail.com>
> Reply-To: "OpenStack Development Mailing List (not for usage questions)" <
> openstack-dev at lists.openstack.org>
> Date: Tuesday, June 3, 2014 at 9:16 AM
> To: "OpenStack Development Mailing List (not for usage questions)" <
> openstack-dev at lists.openstack.org>
> Subject: [openstack-dev] [Cinder] How to mock the LOG inside cinder driver
>
>      <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
> <deepakcs> and then doing...
> <deepakcs> mock_logger.warning.assert_called_once() - which passes and is
> expected to pass per my code
> <deepakcs> but
> <deepakcs> mock_logger.debug.assert_called_once() - shud fail , but this
> also passes !
> <deepakcs> any idea why ?
>
>  I feel that I am not mocking the LOG inside the driver correctly.
>
> I also tried
>            mock.patch.object(glusterfs.LOG, 'warning'),
>             mock.patch.object(glusterfs.LOG, 'debug')
>  as mock_logger_warn and mock_logger_debug respectively
>
>  But here too
>  .debug and .warning both passes.. while the expected result is for
> .warning to pass and .debug to fail
>
>  So somehow I am unable to mock LOG properly
>
> thanx,
> deepak
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20140604/4d83fa9b/attachment.html>


More information about the OpenStack-dev mailing list