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

Deepak Shetty dpkshetty at gmail.com
Wed Jun 4 05:22:16 UTC 2014


The below issue was resolved (thanks to akerr on IRC).
It seems called_once_with is not a function of mock and doesn't work
properly
Need to use assertTrue(mock_func.called) and thats working for me.

thanx,
deepak


On Tue, Jun 3, 2014 at 9:46 PM, Deepak Shetty <dpkshetty at gmail.com> wrote:

> <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/43bbab4f/attachment.html>


More information about the OpenStack-dev mailing list