Best Python code snippet using slash
warnings.py
Source:warnings.py  
...22        warnings.filterwarnings('ignore', category=ImportWarning)23        with warning_callback_context(self._capture_native_warning):24            yield25    def _capture_native_warning(self, message, category, filename, lineno, file=None, line=None): # pylint: disable=unused-argument26        warning = RecordedWarning.from_native_warning(message, category, filename, lineno)27        self.add(warning)28        if not issubclass(category, LogbookWarning):29            _native_logger.warning('{filename}:{lineno}: {warning!r}', filename=filename, lineno=lineno, warning=warning)30    def add(self, warning):31        hooks.warning_added(warning=warning) # pylint: disable=no-member32        self.warnings.append(warning)33    def __iter__(self):34        "Iterates through stored warnings"35        return iter(self.warnings)36    def __len__(self):37        return len(self.warnings)38    def __nonzero__(self):39        return bool(self.warnings)40    __bool__ = __nonzero__41class WarnHandler(logbook.Handler, logbook.StringFormatterHandlerMixin):42    """43    Like a stream handler but keeps the values in memory.44    This logger provides some ways to store warnings to log again at the end of the session.45    """46    default_format_string = (u'[{record.time:%Y-%m-%d %H:%M}] '47      '{record.level_name}: {record.extra[source]}: {record.message}')48    def __init__(self, session_warnings, format_string=None, filter=None, bubble=True):49        logbook.Handler.__init__(self, logbook.WARNING, filter, bubble)50        logbook.StringFormatterHandlerMixin.__init__(self, format_string)51        self.session_warnings = session_warnings52    def should_handle(self, record):53        """Returns `True` if this record is a warning """54        if record.channel == _native_logger.name:55            return False56        return record.level == self.level57    def emit(self, record):58        warnings.warn_explicit(message=record.message, category=LogbookWarning, filename=record.filename,59                               lineno=record.lineno, module=record.module)60WarningKey = collections.namedtuple("WarningKey", ("filename", "lineno"))61class RecordedWarning(object):62    def __init__(self, details, message):63        super(RecordedWarning, self).__init__()64        self.details = details65        self.details['session_id'] = context.session_id66        self.details['test_id'] = context.test_id67        self.details.setdefault('func_name', None)68        self.key = WarningKey(filename=self.details['filename'], lineno=self.details['lineno'])69        self._repr = message70    @classmethod71    def from_log_record(cls, record, handler):72        details = record.to_dict()73        return cls(details, handler.format(record))74    @classmethod75    def from_native_warning(cls, message, category, filename, lineno):76        if isinstance(message, Warning):77            message = message.args[0]78        return cls({79            'message': message,80            'type': category.__name__,81            'filename': filename,82            'lineno': lineno,83            }, message=message)84    @property85    def message(self):86        return self.details.get('message')87    @property88    def lineno(self):89        return self.details.get('lineno')...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
