def test_suppress(self): with self.assertNotRaises(): with suppress(Exception): raise Exception() with self.assertNotRaises(): with suppress(OSError, AttributeError): raise AttributeError() with self.assertRaises(AttributeError): with suppress(OSError): raise AttributeError() with self.assertRaises(RuntimeError): with suppress(OSError, AttributeError): raise RuntimeError()
def remove(device): sroute = DynamicSourceRoute(device, None, None, None) routes, rules = sroute.current_srconfig() logging.debug('Removing source route for device %s', device) try: for route in routes: with suppress(IPRouteDeleteError): # The kernel or dhclient has won the race and removed # the route already. IPRoute.delete(route) for rule in rules: IPRule.delete(rule) except (IPRouteError, IPRuleError) as e: logging.error('Failed source route removal: %s', e.args)