def warns(expected_warning, *args, **kwargs):
 wcheck = WarningsChecker(expected_warning)
 if (not args):
  return wcheck
 elif isinstance(args[0], str):
  (code,) = args
  assert isinstance(code, str)
  frame = sys._getframe(1)
  loc = frame.f_locals.copy()
  loc.update(kwargs)
  with wcheck:
   code = _pytest._code.Source(code).compile()
   py.builtin.exec_(code, frame.f_globals, loc)
 else:
  func = args[0]
  with wcheck:
   return func(*args[1:], **kwargs)

def warns ( expected_warning , * args , ** kwargs ) : wcheck = WarningsChecker ( expected_warning ) if ( not args ) : return wcheck elif isinstance ( args [ 0 ] , str ) : ( code , ) = args assert isinstance ( code , str ) frame = sys . _getframe ( 1 ) loc = frame . f_locals . copy ( ) loc . update ( kwargs ) with wcheck : code = _pytest . _code . Source ( code ) . compile ( ) py . builtin . exec_ ( code , frame . f_globals , loc ) else : func = args [ 0 ] with wcheck : return func ( * args [ 1 : ] , ** kwargs )
assert that code raises a particular class of warning .