Best Python code snippet using lisa_python
testsuite.py
Source:testsuite.py  
...491            ).as_posix()492            case_result.set_status(TestStatus.RUNNING, "")493            case_timeout = case_result.runtime_data.metadata.timeout494            if is_continue:495                is_continue = self.__before_case(496                    case_result=case_result,497                    timeout=case_timeout,498                    test_kwargs=case_kwargs,499                    log=case_log,500                )501            else:502                case_result.stacktrace = suite_error_stacktrace503                case_result.set_status(TestStatus.SKIPPED, suite_error_message)504            if is_continue:505                self.__run_case(506                    case_result=case_result,507                    timeout=case_timeout,508                    test_kwargs=case_kwargs,509                    log=case_log,510                )511            self.__after_case(512                case_result=case_result,513                timeout=case_timeout,514                test_kwargs=case_kwargs,515                log=case_log,516            )517            case_log.info(518                f"result: {case_result.status.name}, " f"elapsed: {total_timer}"519            )520            remove_handler(case_log_handler, case_log)521            remove_handler(case_log_handler, environment.log)522            if case_log_handler:523                case_log_handler.close()524            if self._should_stop:525                suite_log.info("received stop message, stop run")526                break527        self.__suite_method(self.after_suite, test_kwargs=test_kwargs, log=suite_log)528    def stop(self) -> None:529        self._should_stop = True530    def __create_case_log_path(self, case_name: str) -> Path:531        while True:532            path = (533                constants.RUN_LOCAL_LOG_PATH534                / "tests"535                / f"{get_datetime_path()}-{case_name}"536            )537            if not path.exists():538                break539            sleep(0.1)540        # avoid to create folder for UT541        if not is_unittest():542            path.mkdir(parents=True)543        return path544    def __get_test_part_path(self, log_path: Path) -> Path:545        if is_unittest():546            return Path()547        return Path(log_path.parts[-2]) / log_path.parts[-1]548    def __get_case_working_path(self, test_part_path: Path) -> Path:549        if is_unittest():550            return Path()551        # The working path should be the same name as log_path, so it's easy to552        # associated. Unlike the log path, the working path won't be created, because553        # it's not used in most cases. So it doesn't need to be created too. The554        # test case should create it, when it's used.555        working_path = constants.RUN_LOCAL_WORKING_PATH / test_part_path556        return working_path557    def __suite_method(558        self, method: Callable[..., Any], test_kwargs: Dict[str, Any], log: Logger559    ) -> Tuple[bool, str, Optional[str]]:560        result: bool = True561        message: str = ""562        timer = create_timer()563        method_name = method.__name__564        stacktrace: Optional[str] = None565        try:566            self.__call_with_retry_and_timeout(567                method,568                retries=0,569                timeout=3600,570                log=log,571                test_kwargs=test_kwargs,572            )573        except Exception as identifier:574            result = False575            message = f"{method_name}: {identifier}"576            stacktrace = traceback.format_exc()577        log.debug(f"{method_name} end in {timer}")578        return result, message, stacktrace579    def __before_case(580        self,581        case_result: TestResult,582        timeout: int,583        test_kwargs: Dict[str, Any],584        log: Logger,585    ) -> bool:586        result: bool = True587        timer = create_timer()588        try:589            self.__call_with_retry_and_timeout(590                self.before_case,591                retries=case_result.runtime_data.retry,592                timeout=timeout,593                log=log,...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!!
