def test_kill_processes(self): with contextlib.nested( self.mock_method('%s.pid.os.kill' % __name__, None, None), self.mock_method('%s.pid.is_process_alive' % __name__, False, None) ): # this should run fine, all processes are dead pids = [1, 2, 3, 4, 5] pid.kill_processes(pids) T.assert_equal(pids, [])
def test_kill_dead_processes(self): def side_effect(*args, **kwargs): raise OSError(errno.ESRCH, "process is dead already...") with contextlib.nested( self.mock_method('%s.pid.os.kill' % __name__, False, side_effect), self.mock_method('%s.pid.is_process_alive' % __name__, True, None) ): # this should run fine too, all processes # (coincidentally) died just before we try killing # them. pids = [1, 2, 3, 4, 5] pid.kill_processes(pids) T.assert_equal(pids, [])