derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Add patch.stopall function #154

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When creating a lot of patches in setUp, they current method is to create the 
patches (storing them in the TestCase), start them all and the stop them all in 
tearDown.  This is rather cumbersome, especially when the patch object itself 
isn't actually needed.  For example:

{{{
    def setUp(self):
        self.patch1 = patch('object1')
        self.patch2 = patch('object2')
        self.patch3 = patch('object2')
        self.patch4 = patch('object2')
        self.patch1.start()
        self.patch2.start()
        self.patch3.start()
        self.patch4.start()

    def tearDown(self):
        self.patch1.stop()
        self.patch2.stop()
        self.patch3.stop()
        self.patch4.stop()
}}}

It would be really useful to be able to simplify this to

{{{
    def setUp(self):
        patch('object1').start()
        patch('object2').start()
        patch('object2').start()
        patch('object2').start()

    def tearDown(self):
        patch.stopall()
}}}

where patch.stopall() simply stops all active patches.

I've attached a patch with a simple implementation of this (including a test 
and documentation).

Original issue reported on code.google.com by aquavita...@gmail.com on 13 Apr 2012 at 7:51

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 13 Apr 2012 at 8:19

GoogleCodeExporter commented 9 years ago
Yes, good idea.

Original comment by fuzzyman on 14 Apr 2012 at 9:52

GoogleCodeExporter commented 9 years ago
A modified version of this is now on trunk.

Original comment by fuzzyman on 10 Jun 2012 at 8:14

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 10 Jun 2012 at 8:18