Best Python code snippet using slash
console_reporter.py
Source:console_reporter.py
...141 for index, (test_index, test_result, infos) in enumerate(self._iter_reported_results(session)):142 if index == 0:143 self._terminal.sep('=', 'Session Summary', **header_format)144 self._report_test_summary_header(test_index, test_result)145 self._report_additional_test_details(test_result)146 for info_reporter in infos:147 info_reporter(test_result)148 if self._verobsity_allows(VERBOSITIES.WARNING):149 self._report_result_warning_summary(session)150 msg = 'Session ended.'151 msg += ' {} successful, {} skipped, {} failed, {} erroneous.'.format(152 session.results.get_num_successful(153 ), session.results.get_num_skipped(include_not_run=False),154 session.results.get_num_failures(), session.results.get_num_errors())155 not_run = session.results.get_num_not_run()156 if not_run:157 msg += ' {} not run.'.format(not_run)158 if (session.has_children() and session.parallel_manager.server159 and session.parallel_manager.server.worker_error_reported):160 msg += " Found session errors in children."161 msg += ' Total duration: {}'.format(162 self._format_duration(session.duration))163 self._terminal.sep('=', msg, **header_format)164 def _get_session_summary_header_format(self, session):165 if session.results.is_success(allow_skips=True):166 return theme('session-summary-success')167 return theme('session-summary-failure')168 def _iter_reported_results(self, session):169 for test_index, test_result in enumerate(session.results.iter_test_results()):170 infos = self._get_result_info_generators(test_result)171 if not infos:172 continue173 yield test_index, test_result, infos174 def _report_test_summary_header(self, index, test_result):175 self._terminal.lsep(176 "=", '== #{}: {}'.format(index + 1, test_result.test_metadata.address), **theme('test-error-header'))177 def _get_result_info_generators(self, test_result):178 returned = []179 if self._verobsity_allows(VERBOSITIES.ERROR) and test_result.has_errors_or_failures():180 returned.append(self._report_result_errors_failures)181 if self._verobsity_allows(VERBOSITIES.INFO) and test_result.has_skips():182 returned.append(self._report_result_skip_summary)183 return returned184 def _report_result_warning_summary(self, session):185 warnings_by_key = {}186 for warning in session.warnings:187 warnings_by_key.setdefault(warning.key, []).append(warning)188 for i, warnings in iteration(warnings_by_key.values()):189 if i.first:190 self._terminal.sep(191 '=', 'Warnings ({} total)'.format(len(session.warnings)), yellow=True)192 self._terminal.write(193 ' * {d[filename]}:{d[lineno]:03} -- '.format(d=warnings[0].details), yellow=True)194 self._terminal.write(195 warnings[0].details['message'], yellow=True, bold=True)196 self._terminal.write(197 ' (Repeated {} times)\n'.format(len(warnings)), yellow=True)198 def _verobsity_allows(self, level):199 return self._level <= level200 def _report_result_errors_failures(self, test_result):201 all_errs = list(202 itertools.chain(zip(itertools.repeat("E"), test_result.get_errors()),203 zip(itertools.repeat("F"), test_result.get_failures())))204 for index, (err_type, err) in enumerate(all_errs):205 if err.exception_type is None and not config.root.log.show_manual_errors_tb:206 self._terminal.write(err.message, **theme('tb-error'))207 self._terminal.write('\n')208 continue209 err_header = ' - {0}/{1} {2} ({3:YYYY-MM-DD HH:mm:ss ZZ}): {4}'.format(210 index + 1,211 len(all_errs),212 err_type,213 err.time.to('local'),214 ' - {}'.format(err.message) if not err.traceback else '')215 self._terminal.lsep(' -', err_header, **theme('error-separator-dash'))216 if err.has_custom_message():217 self._terminal.write(' {}\n'.format(err.message), **theme('tb-error-message'))218 self._report_traceback(err_type, err)219 def _report_traceback(self, err_type, err):220 console_traceback_level = config.root.log.console_traceback_level221 if not err.traceback or console_traceback_level == NO_TRACEBACK:222 frames = []223 elif console_traceback_level == SINGLE_FRAME:224 frames = [err.traceback.frames[-1]]225 else:226 frames = err.traceback.frames227 for frame_iteration, frame in iteration(frames):228 if console_traceback_level >= ALL_FRAMES_WITH_CONTEXT_AND_VARS:229 if not frame_iteration.first:230 self._terminal.sep('- ')231 self._terminal.write(232 ' {}:{}\n'.format(frame.filename, frame.lineno), **theme('tb-frame-location'))233 if console_traceback_level >= ALL_FRAMES_WITH_CONTEXT_AND_VARS:234 self._write_frame_locals(frame)235 self._write_frame_code(236 frame, include_context=(console_traceback_level >= ALL_FRAMES_WITH_CONTEXT))237 if frame_iteration.last:238 self._terminal.write(err_type, **theme('tb-error'))239 self._terminal.write(240 self._indent_with(err.message, 4), **theme('tb-error'))241 self._terminal.write('\n')242 def _report_additional_test_details(self, result):243 if result.is_success():244 return245 detail_items = result.details.all().items()246 log_path = result.get_log_path()247 if log_path is not None:248 detail_items = itertools.chain(detail_items, [('Log', log_path)])249 for index, (key, value) in enumerate(detail_items):250 if index == 0:251 self._terminal.write(' - Additional Details:\n', **theme('test-additional-details-header'))252 self._terminal.write(' > {}: {!r}\n'.format(key, value), **theme('test-additional-details'))253 def _indent_with(self, text, indent):254 if isinstance(indent, int):255 indent = ' ' * indent256 return '\n'.join(indent + line for line in text.splitlines())...
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!!