How to use make_tags_from_test_tree_node method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

reportportal.py

Source:reportportal.py Github

copy

Full Screen

...14from lemoncheesecake.events import SyncEventManager15from lemoncheesecake.reporting.replay import replay_report_events16def make_time(t):17 return str(int(t * 1000))18def make_tags_from_test_tree_node(node):19 return node.tags + \20 ["%s_%s" % (name, value) for name, value in node.properties.items()] + \21 [link[1] or link[0] for link in node.links]22class ReportPortalReportingSession(ReportingSession):23 def __init__(self, url, auth_token, project, launch_name, launch_description, report_dir, report):24 self.service = reportportal_client.ReportPortalServiceAsync(25 endpoint=url, project=project, token=auth_token, error_handler=self._handle_rp_error26 )27 self.launch_name = launch_name28 self.launch_description = launch_description29 self.report_dir = report_dir30 self.report = report31 self._rp_exc_info = None32 def _handle_rp_error(self, exc_info):33 self._rp_exc_info = exc_info34 return False # stop on error35 def _has_rp_error(self):36 return self._rp_exc_info is not None37 def _show_rp_error(self):38 print(39 "Got the following exception using ReportPortal, "40 "test results have not been properly synced:",41 file=sys.stderr42 )43 traceback.print_exception(*self._rp_exc_info, file=sys.stderr)44 def _end_current_test_item(self, end_time, status):45 self.service.finish_test_item(end_time=make_time(end_time), status=status)46 def _start_test_item(self, item_type, start_time, name, description, wrapped=False):47 if wrapped:48 self.service.start_test_item(49 item_type="SUITE", start_time=make_time(start_time),50 name=name, description=description51 )52 self.service.start_test_item(53 item_type=item_type, start_time=make_time(start_time),54 name=name, description=description55 )56 def _end_test_item(self, end_time, is_successful, wrapped=False):57 status = "passed" if is_successful else "failed"58 if wrapped:59 self._end_current_test_item(end_time, status=status)60 self._end_current_test_item(end_time, status=status)61 def on_test_session_start(self, event):62 if self._has_rp_error():63 return64 self.service.start_launch(65 name=self.launch_name, description=self.launch_description, start_time=make_time(event.time)66 )67 def on_test_session_end(self, event):68 if self._has_rp_error():69 self._show_rp_error()70 else:71 self.service.finish_launch(end_time=make_time(event.time))72 self.service.terminate()73 if self._has_rp_error():74 self._show_rp_error()75 def on_test_session_setup_start(self, event):76 if self._has_rp_error():77 return78 self._start_test_item(79 item_type="BEFORE_CLASS", start_time=event.time,80 name="session_setup", description="Test Session Setup",81 wrapped=True82 )83 def on_test_session_setup_end(self, event):84 if self._has_rp_error():85 return86 self._end_test_item(87 event.time,88 not self.report.test_session_setup or self.report.test_session_setup.is_successful(),89 wrapped=True90 )91 def on_test_session_teardown_start(self, event):92 if self._has_rp_error():93 return94 self._start_test_item(95 item_type="AFTER_CLASS", start_time=event.time,96 name="session_teardown", description="Test Session Teardown",97 wrapped=True98 )99 def on_test_session_teardown_end(self, event):100 if self._has_rp_error():101 return102 self._end_test_item(103 event.time,104 not self.report.test_session_teardown or self.report.test_session_teardown.is_successful(),105 wrapped=True106 )107 def on_suite_start(self, event):108 if self._has_rp_error():109 return110 suite = event.suite111 self.service.start_test_item(112 item_type="SUITE", start_time=make_time(event.time),113 name=suite.name, description=suite.description,114 tags=make_tags_from_test_tree_node(suite)115 )116 def on_suite_end(self, event):117 if self._has_rp_error():118 return119 self._end_current_test_item(event.time, status="passed")120 def on_suite_setup_start(self, event):121 if self._has_rp_error():122 return123 self._start_test_item(124 item_type="BEFORE_CLASS", start_time=event.time,125 name="suite_setup", description="Suite Setup",126 wrapped=len(event.suite.get_suites()) > 0127 )128 def on_suite_setup_end(self, event):129 if self._has_rp_error():130 return131 suite_data = self.report.get_suite(event.suite)132 self._end_test_item(133 event.time,134 not suite_data.suite_setup or suite_data.suite_setup.is_successful(),135 wrapped=len(event.suite.get_suites()) > 0136 )137 def on_suite_teardown_start(self, event):138 if self._has_rp_error():139 return140 self._start_test_item(141 item_type="AFTER_CLASS", start_time=event.time,142 name="suite_teardown", description="Suite Teardown",143 wrapped=len(event.suite.get_suites()) > 0144 )145 def on_suite_teardown_end(self, event):146 if self._has_rp_error():147 return148 suite_data = self.report.get_suite(event.suite)149 self._end_test_item(150 event.time,151 not suite_data.suite_teardown or suite_data.suite_teardown.is_successful(),152 wrapped=len(event.suite.get_suites()) > 0153 )154 def on_test_start(self, event):155 if self._has_rp_error():156 return157 test = event.test158 self.service.start_test_item(159 item_type="TEST", start_time=make_time(event.time),160 name=test.name, description=test.description,161 tags=make_tags_from_test_tree_node(test)162 )163 def on_test_end(self, event):164 if self._has_rp_error():165 return166 test_data = self.report.get_test(event.test)167 self._end_current_test_item(event.time, test_data.status)168 def _bypass_test(self, test, status, time):169 if self._has_rp_error():170 return171 self.service.start_test_item(172 item_type="TEST", start_time=make_time(time),173 name=test.name, description=test.description, tags=test.tags,174 )175 self._end_current_test_item(time, status=status)...

Full Screen

Full Screen

test_report_reportportal.py

Source:test_report_reportportal.py Github

copy

Full Screen

...20def substr(value):21 return re.compile(re.escape(value))22def convert_status(status):23 return "passed" if status == "passed" else "failed"24def make_tags_from_test_tree_node(node):25 return node.tags + \26 ["%s_%s" % (name, value) for name, value in node.properties.items()] + \27 [link[1] or link[0] for link in node.links]28def assert_rp_calls(actual_calls, expected_calls):29 pattern_type = type(re.compile(r"foo"))30 int_as_str_pattern = re.compile(r"^(\d+)$")31 for actual_call, expected_call in zip(actual_calls, expected_calls):32 actual_name, actual_args, actual_kwargs = actual_call33 expected_name, expected_args, expected_kwargs = expected_call34 # method name:35 assert actual_name == expected_name36 # args:37 if actual_name == "log":38 assert int_as_str_pattern.match(actual_args[0]) is not None39 actual_args = actual_args[1:]40 for actual_arg, expected_arg in zip(actual_args, expected_args):41 if type(expected_arg) is pattern_type:42 assert expected_arg.search(actual_arg) is not None43 else:44 assert actual_arg == expected_arg45 # kwargs:46 for name, value in expected_kwargs.items():47 assert actual_kwargs[name] == value48 if actual_name.startswith("start_"):49 assert int_as_str_pattern.match(actual_kwargs["start_time"]) is not None50 if actual_name.startswith("finish_"):51 assert int_as_str_pattern.match(actual_kwargs["end_time"]) is not None52 assert len(actual_calls) == len(expected_calls)53def steps_to_calls(steps):54 for step in steps:55 yield "log", (substr(step.description), 'INFO'), {}56 for log in step.get_logs():57 if isinstance(log, Log):58 yield "log", (log.message, log.level.upper()), {}59 if isinstance(log, Check):60 message = "%s => %s" % (log.description, "OK" if log.is_successful else "NOT OK")61 if log.details:62 message += "\nDetails: %s" % log.details63 level = "INFO" if log.is_successful else "ERROR"64 yield "log", (message, level), {}65 if isinstance(log, Url):66 yield "log", (substr(log.url), "INFO"), {}67 if isinstance(log, Attachment):68 with open(log.filename, "rb") as fh:69 attachment_content = fh.read()70 attachment_arg = {71 "name": osp.basename(log.filename),72 "data": attachment_content,73 "mime": mimetypes.guess_type(log.filename)[0] or "application/octet-stream"74 }75 yield "log", (log.description, "INFO"), {"attachment": attachment_arg}76def start_test_item(item_type, name, description, tags=None):77 kwargs = {"item_type": item_type, "name": name, "description": description}78 if tags is not None:79 kwargs["tags"] = tags80 return "start_test_item", (), kwargs81def finish_test_item(status):82 return "finish_test_item", (), {"status": status}83def _tests_to_rp_calls(tests):84 for test in tests:85 yield start_test_item("TEST", test.name, test.description, make_tags_from_test_tree_node(test))86 for call in steps_to_calls(test.get_steps()):87 yield call88 yield finish_test_item(test.status)89def suites_to_rp_calls(suites):90 for suite in suites:91 # START SUITE92 yield start_test_item("SUITE", suite.name, suite.description, make_tags_from_test_tree_node(suite))93 # SUITE SETUP94 if suite.suite_setup:95 yield start_test_item("BEFORE_CLASS", "suite_setup", "Suite Setup")96 for call in steps_to_calls(suite.suite_setup.get_steps()):97 yield call98 yield finish_test_item(suite.suite_setup.status)99 # TESTS100 for call in _tests_to_rp_calls(suite.get_tests()):101 yield call102 # SUB SUITES103 for call in suites_to_rp_calls(suite.get_suites()):104 yield call105 # SUITE TEARDOWN106 if suite.suite_teardown:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful