On Wed, Sep 23, 2015 at 3:06 AM, liuxinguo <liuxin...@huawei.com> wrote:
> 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: > > clas*s 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) > > clas*s 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! > > > Use oslotest's mockpatch.PatchObject fixture: http://docs.openstack.org/developer/oslotest/api.html#oslotest.mockpatch.PatchObject > Wilson Liu > > __________________________________________________________________________ > OpenStack Development Mailing List (not for usage questions) > Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev > >
__________________________________________________________________________ OpenStack Development Mailing List (not for usage questions) Unsubscribe: openstack-dev-requ...@lists.openstack.org?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev