[openstack-dev] [cinder] How to make a mock effactive for all method of a testclass

liuxinguo liuxinguo at huawei.com
Wed Sep 23 08:06:04 UTC 2015


Hi,

In a.py we have a function:
def _change_file_mode(filepath):
utils.execute('chmod', '600', filepath, run_as_root=True)

In test_xxx.py, there is a testclass:
class xxxxDriverTestCase(test.TestCase):
def test_a(self)
    ...
    Call a. _change_file_mode
...

def test_b(self)
    ...
    Call a. _change_file_mode
...

I have tried to mock like mock out function _change_file_mode like this:
@mock.patch.object(a, '_change_file_mode', return_value=None)
class xxxxDriverTestCase(test.TestCase):
def test_a(self)
    ...
    Call a. _change_file_mode
...

def test_b(self)
    ...
    Call a. _change_file_mode
...

But the mock takes no effort, the real function _change_file_mode is still executed.
So how to make a mock effactive for all method of a testclass?
Thanks for any input!

Wilson Liu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20150923/d577470a/attachment.html>


More information about the OpenStack-dev mailing list