def add_debugging_monkeypatches():
 from twisted.application.service import Service
 old_startService = Service.startService
 old_stopService = Service.stopService
 def startService(self):
  assert (not self.running)
  return old_startService(self)
 def stopService(self):
  assert self.running
  return old_stopService(self)
 Service.startService = startService
 Service.stopService = stopService
 if ((twisted.version.major <= 9) and (sys.version_info[:2] == (2, 7))):
  def nopatch(self, *args):
   raise unittest.SkipTest('unittest.TestCase.patch is not available')
  unittest.TestCase.patch = nopatch

def add_debugging_monkeypatches ( ) : from twisted . application . service import Service old_startService = Service . startService old_stopService = Service . stopService def startService ( self ) : assert ( not self . running ) return old_startService ( self ) def stopService ( self ) : assert self . running return old_stopService ( self ) Service . startService = startService Service . stopService = stopService if ( ( twisted . version . major <= 9 ) and ( sys . version_info [ : 2 ] == ( 2 , 7 ) ) ) : def nopatch ( self , * args ) : raise unittest . SkipTest ( 'unittest.TestCase.patch is not available' ) unittest . TestCase . patch = nopatch
do not call this directly this adds a few "harmless" monkeypatches which make it easier to debug failing tests .