Best Python code snippet using slash
app.py
Source:app.py
...84 self._exit_stack.__enter__()85 try:86 self._exit_stack.enter_context(self._prelude_logging_context())87 self._exit_stack.enter_context(self._prelude_warning_context())88 self._exit_stack.enter_context(self._sigterm_context())89 with dessert.rewrite_assertions_context():90 site.load(working_directory=self._working_directory)91 cli_utils.configure_arg_parser_by_plugins(self.arg_parser)92 cli_utils.configure_arg_parser_by_config(self.arg_parser)93 argv = cli_utils.add_pending_plugins_from_commandline(self._get_argv())94 self._parsed_args, self._positional_args = self.arg_parser.parse_known_args(argv)95 self._exit_stack.enter_context(96 cli_utils.get_modified_configuration_from_args_context(self.arg_parser, self._parsed_args)97 )98 self.session = Session(reporter=self.get_reporter(), console_stream=self._report_stream)99 trigger_hook.configure() # pylint: disable=no-member100 plugins.manager.configure_for_parallel_mode()101 plugins.manager.activate_pending_plugins()102 cli_utils.configure_plugins_from_args(self._parsed_args)103 self._exit_stack.enter_context(self.session)104 self._emit_prelude_logs()105 self._emit_prelude_warnings()106 return self107 except:108 self._emit_prelude_logs()109 self.__exit__(*sys.exc_info())110 raise111 def __exit__(self, exc_type, exc_value, exc_tb):112 exc_info = (exc_type, exc_value, exc_tb)113 try:114 debug_if_needed(exc_info)115 except Exception as e: # pylint: disable=broad-except116 _logger.error("Failed to debug_if_needed: {!r}", e, exc_info=True, extra={'capture': False})117 if exc_value is not None:118 self._exit_code = exc_value.code if isinstance(exc_value, SystemExit) else 1119 if should_inhibit_unhandled_exception_traceback(exc_value):120 self.get_reporter().report_error_message(str(exc_value))121 elif isinstance(exc_value, Exception):122 _logger.error('Unexpected error occurred', exc_info=exc_info, extra={'capture': False})123 self.get_reporter().report_error_message('Unexpected error: {}'.format(exc_value))124 if isinstance(exc_value, exceptions.INTERRUPTION_EXCEPTIONS):125 self._interrupted = True126 if exc_type is not None:127 trigger_hook.result_summary() # pylint: disable=no-member128 self._exit_stack.__exit__(exc_type, exc_value, exc_tb)129 self._exit_stack = None130 self._reset_parser()131 trigger_hook.app_quit() # pylint: disable=no-member132 return True133 def _capture_native_warning(self, message, category, filename, lineno, file=None, line=None): # pylint: disable=unused-argument134 self._prelude_warning_records.append(RecordedWarning.from_native_warning(message, category, filename, lineno))135 def _prelude_logging_context(self):136 self._prelude_log_handler = log.RetainedLogHandler(bubble=True, level=logbook.TRACE)137 return self._prelude_log_handler.applicationbound()138 def _prelude_warning_context(self):139 capture_all_warnings()140 return warning_callback_context(self._capture_native_warning)141 def _emit_prelude_warnings(self):142 if self.session is not None:143 for warning in self._prelude_warning_records:144 if not self.session.warnings.warning_should_be_filtered(warning):145 self.session.warnings.add(warning)146 def _emit_prelude_logs(self):147 self._prelude_log_handler.disable()148 handler = None149 if self.session is not None:150 handler = self.session.logging.session_log_handler151 if handler is None:152 handler = self._console_handler153 self._prelude_log_handler.flush_to_handler(handler)154 @contextmanager155 def _sigterm_context(self):156 def handle_sigterm(*_):157 with handling_exceptions():158 raise TerminatedException('Terminated by signal')159 prev = signal.signal(signal.SIGTERM, handle_sigterm)160 try:161 yield162 finally:163 try:164 signal.signal(signal.SIGTERM, prev)165 except TypeError as e:166 #workaround for a strange issue on app cleanup. See https://bugs.python.org/issue23548167 if 'signal handler must be signal.SIG_IGN' not in str(e):...
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!!