def _filterwarnings(filters, quiet=False):
 frame = sys._getframe(2)
 registry = frame.f_globals.get('__warningregistry__')
 if registry:
  registry.clear()
 with warnings.catch_warnings(record=True) as w:
  sys.modules['warnings'].simplefilter('always')
  (yield WarningsRecorder(w))
 reraise = [warning.message for warning in w]
 missing = []
 for (msg, cat) in filters:
  seen = False
  for exc in reraise[:]:
   message = str(exc)
   if (re.match(msg, message, re.I) and issubclass(exc.__class__, cat)):
    seen = True
    reraise.remove(exc)
  if ((not seen) and (not quiet)):
   missing.append((msg, cat.__name__))
 if reraise:
  raise AssertionError(('unhandled warning %r' % reraise[0]))
 if missing:
  raise AssertionError(('filter (%r, %s) did not catch any warning' % missing[0]))

def _filterwarnings ( filters , quiet = False ) : frame = sys . _getframe ( 2 ) registry = frame . f_globals . get ( '__warningregistry__' ) if registry : registry . clear ( ) with warnings . catch_warnings ( record = True ) as w : sys . modules [ 'warnings' ] . simplefilter ( 'always' ) ( yield WarningsRecorder ( w ) ) reraise = [ warning . message for warning in w ] missing = [ ] for ( msg , cat ) in filters : seen = False for exc in reraise [ : ] : message = str ( exc ) if ( re . match ( msg , message , re . I ) and issubclass ( exc . __class__ , cat ) ) : seen = True reraise . remove ( exc ) if ( ( not seen ) and ( not quiet ) ) : missing . append ( ( msg , cat . __name__ ) ) if reraise : raise AssertionError ( ( 'unhandled warning %r' % reraise [ 0 ] ) ) if missing : raise AssertionError ( ( 'filter (%r, %s) did not catch any warning' % missing [ 0 ] ) )
catch the warnings .