Best Python code snippet using lisa_python
lisa_runner.py
Source:lisa_runner.py  
...375                if self._is_awaitable_timeout("prepare"):376                    raise SkippedException(identifier)377        except Exception as identifier:378            success = False379            matched_result = self._match_failed_environment_with_result(380                environment=environment,381                candidate_results=self.test_results,382                exception=identifier,383            )384            self._attach_failed_environment_to_result(385                environment=environment,386                result=matched_result,387                exception=identifier,388            )389        return success390    def _cleanup_deleted_environments(self) -> None:391        # remove reference to unused environments. It can save memory on big runs.392        new_environments: List[Environment] = []393        for environment in self.environments[:]:394            if environment.status != EnvironmentStatus.Deleted:395                new_environments.append(environment)396        self.environments = new_environments397    def _cleanup_done_results(self) -> None:398        # remove reference to completed test results. It can save memory on big runs.399        remaining_results: List[TestResult] = []400        for test_result in self.test_results[:]:401            if not test_result.is_completed:402                remaining_results.append(test_result)403        self.test_results = remaining_results404    def _get_results_by_priority(405        self, test_results: List[TestResult], priority: int406    ) -> List[TestResult]:407        if not test_results:408            return []409        test_results = [410            x for x in test_results if x.runtime_data.metadata.priority == priority411        ]412        return test_results413    def _generate_task(414        self,415        task_method: Callable[..., None],416        environment: Environment,417        test_results: List[TestResult],418        **kwargs: Any,419    ) -> Task[None]:420        assert not environment.is_in_use421        environment.is_in_use = True422        for test_result in test_results:423            # return assigned but not run cases424            if test_result.status == TestStatus.QUEUED:425                test_result.set_status(TestStatus.ASSIGNED, "")426        task = partial(427            self._run_task,428            task_method,429            environment=environment,430            test_results=test_results,431            **kwargs,432        )433        return Task(self.generate_task_id(), task, self._log)434    def _run_task(435        self,436        task_method: Callable[..., None],437        environment: Environment,438        test_results: List[TestResult],439        **kwargs: Any,440    ) -> None:441        assert environment.is_in_use442        task_method(environment=environment, test_results=test_results, **kwargs)443        for test_result in test_results:444            # return assigned but not run cases445            if test_result.status == TestStatus.ASSIGNED:446                test_result.set_status(TestStatus.QUEUED, "")447        environment.is_in_use = False448    def _match_failed_environment_with_result(449        self,450        environment: Environment,451        candidate_results: List[TestResult],452        exception: Exception,453    ) -> TestResult:454        if environment.source_test_result and environment.source_test_result.is_queued:455            matched_results = [environment.source_test_result]456        else:457            matched_results = self._get_runnable_test_results(458                test_results=candidate_results,459                environment=environment,460            )461        if not matched_results:462            self._log.info(...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!!
