1

I'm charged with adding a unit test to an existing TestCase object. The setup method instantiates and starts several unittest.patch objects on functions that I need to test unmocked. Is calling stop() on the relevant patch before running my tests, then calling patch.start() on the same object a valid approach? Or would the patch have to be reinstantiated after calling stop()? Something like this:

class MyTestCase(unitites.TestCase):
    
    def setup(self):
        self.patch_to_toggle('some.module.Class.method', return='thisOrThat')
        self.patch_to_toggle.start()
        
    def test_toggle_patch(self):
        self.patch_to_toggle.stop()
        result = some.module.Class.method(*args)
        self.assertTrue(...)
        self.patch_to_toggle.start()
Conner M.
  • 1,954
  • 3
  • 19
  • 29

0 Answers0