Best Python code snippet using lemoncheesecake
console.py
Source:console.py
...115 def on_suite_setup_end(self, event):116 self.lp.erase_line()117 self.custom_step_prefix = None118 on_suite_teardown_end = on_suite_setup_end119 def on_test_session_setup_end(self, event):120 self.lp.erase_line()121 self.custom_step_prefix = None122 on_test_session_teardown_end = on_test_session_setup_end123 def on_test_start(self, event):124 self.ensure_suite_header_is_displayed(event.test.parent_suite)125 self.step_prefix = " -- %2s # %s" % (self.current_test_idx, self.get_test_label(event.test))126 self.lp.print_line(self.step_prefix + "...")127 self.previous_obj = event.test128 def on_test_end(self, event):129 test_data = self.report.get_test(event.test)130 line, raw_line_len = _make_test_result_line(131 self.get_test_label(event.test), self.current_test_idx, test_data.status132 )133 self.lp.print_line(line, force_len=raw_line_len)...
writer.py
Source:writer.py
...47 def on_test_session_end(self, event):48 self.report.end_time = event.time49 def on_test_session_setup_start(self, event):50 self.report.test_session_setup = self._initialize_result(event.time)51 def on_test_session_setup_end(self, event):52 self._finalize_result(self.report.test_session_setup, event.time)53 def on_test_session_teardown_start(self, event):54 self.report.test_session_teardown = self._initialize_result(event.time)55 def on_test_session_teardown_end(self, event):56 self._finalize_result(self.report.test_session_teardown, event.time)57 def on_suite_start(self, event):58 suite = event.suite59 suite_result = SuiteResult(suite.name, suite.description)60 suite_result.start_time = event.time61 suite_result.tags.extend(suite.tags)62 suite_result.properties.update(suite.properties)63 suite_result.links.extend(suite.links)64 suite_result.rank = suite.rank65 if suite.parent_suite:...
backend.py
Source:backend.py
1'''2Created on Mar 29, 20163@author: nicolas4'''5import os6from lemoncheesecake.helpers.orderedset import OrderedSet7from lemoncheesecake.exceptions import LemoncheesecakeException8_NEGATION_FLAGS = "-^~"9class ReportingSession(object):10 pass11class ReportingSessionBuilderMixin(object):12 def create_reporting_session(self, report_dir, report, parallel, report_saving_strategy):13 raise NotImplementedError()14class ReportSerializerMixin(object):15 def save_report(self, filename, report):16 raise NotImplementedError()17class ReportUnserializerMixin(object):18 def load_report(self, filename):19 raise NotImplementedError()20class ReportingBackend(object):21 def get_name(self):22 raise NotImplementedError()23 def is_available(self):24 return True25class FileReportSession(ReportingSession):26 def __init__(self, report_filename, report, reporting_backend, report_saving_strategy):27 self.report_filename = report_filename28 self.report = report29 self.reporting_backend = reporting_backend30 self.report_saving_strategy = report_saving_strategy31 def _save(self):32 self.reporting_backend.save_report(self.report_filename, self.report)33 def _handle_event(self, event):34 report_must_be_saved = self.report_saving_strategy and self.report_saving_strategy(event, self.report)35 if report_must_be_saved:36 self._save()37 on_test_session_setup_end = _handle_event38 on_test_session_teardown_end = _handle_event39 on_suite_setup_end = _handle_event40 on_suite_teardown_end = _handle_event41 on_test_end = _handle_event42 on_suite_end = _handle_event43 on_log = _handle_event44 on_log_attachment = _handle_event45 on_log_url = _handle_event46 on_check = _handle_event47 def on_test_session_end(self, event):48 # no matter what is the report_saving_strategy,49 # the report will always be saved at the end of tests50 self._save()51class FileReportBackend(ReportingBackend, ReportSerializerMixin, ReportingSessionBuilderMixin):52 def get_report_filename(self):53 raise NotImplementedError()54 def create_reporting_session(self, report_dir, report, parallel, report_saving_strategy):55 return FileReportSession(56 os.path.join(report_dir, self.get_report_filename()), report, self, report_saving_strategy57 )58def filter_available_reporting_backends(backends):59 return list(filter(lambda backend: backend.is_available(), backends))60def get_reporting_backends():61 from lemoncheesecake.reporting.backends import REPORTING_BACKENDS62 return list(63 filter(64 lambda backend: backend.is_available(),65 (backend_class() for backend_class in REPORTING_BACKENDS)66 )67 )68def get_reporting_backend_names(default_names, custom_names):69 if all(name[0] not in ("+" + _NEGATION_FLAGS) for name in custom_names): # fixed list70 return custom_names71 elif all(name[0] in ("+" + _NEGATION_FLAGS) for name in custom_names): # turn on/off directives72 names = OrderedSet(default_names)73 for specified_name in custom_names:74 if specified_name[0] == "+": # turn on75 names.add(specified_name[1:])76 else: # turn off77 try:78 names.remove(specified_name[1:])79 except KeyError:80 raise ValueError(81 "reporting backend '%s' is not among the default reporting backends" % specified_name[1:]82 )83 return names84 else:85 raise ValueError(86 "either the custom reporting backends must be fixed backend list, "87 "or a list of turn on/off (+ / ^) directives"88 )89def parse_reporting_backend_names_expression(expr):90 return list(filter(bool, expr.split(" ")))91def get_reporting_backend_by_name(name):92 try:93 return next(backend for backend in get_reporting_backends() if backend.get_name() == name)94 except StopIteration:95 raise KeyError()96def get_reporting_backends_for_test_run(available_backends, backend_names):97 backends = []98 for backend_name in backend_names:99 try:100 backend = available_backends[backend_name]101 except KeyError:102 raise LemoncheesecakeException("Unknown reporting backend '%s'" % backend_name)103 if not isinstance(backend, ReportingSessionBuilderMixin):104 raise LemoncheesecakeException("Reporting backend '%s' is not suitable for test run" % backend_name)105 backends.append(backend)...
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!!