Best Python code snippet using avocado_python
loader.py
Source:loader.py  
...439                )440        return tests441    def _make_existing_file_tests(self, test_path, make_broken, subtests_filter):442        if test_path.endswith(".py"):443            return self._make_python_file_tests(test_path, make_broken, subtests_filter)444        else:445            return make_broken(NotATest, test_path, self.NOT_TEST_STR)446    def _make_nonexisting_file_tests(447        self, test_path, make_broken, subtests_filter, test_name448    ):449        # Try to resolve test ID (keep compatibility)450        test_path = os.path.join(data_dir.get_test_dir(), test_name)451        if os.path.exists(test_path):452            return self._make_python_file_tests(453                test_path, make_broken, subtests_filter, test_name454            )455        else:456            if not subtests_filter and ":" in test_name:457                test_name, subtests_filter = test_name.split(":", 1)458                test_path = os.path.join(data_dir.get_test_dir(), test_name)459                if os.path.exists(test_path):460                    subtests_filter = re.compile(subtests_filter)461                    return self._make_python_file_tests(462                        test_path, make_broken, subtests_filter, test_name463                    )464            return make_broken(465                NotATest,466                test_name,467                (f"File not found ('{test_name}'; " f"'{test_path}')"),468            )469    @staticmethod470    def _make_test(471        klass, uid, description=None, subtests_filter=None, **test_arguments472    ):473        """474        Create test template475        :param klass: test class476        :param uid: test uid (by default used as id and name)477        :param description: Description appended to "uid" (for listing purpose)478        :param subtests_filter: optional filter of methods for avocado tests479        :param test_arguments: arguments to be passed to the klass(test_arguments)480        """481        if subtests_filter and not subtests_filter.search(uid):482            return []483        if description:484            uid = f"{uid}: {description}"485        test_arguments["name"] = uid486        return [(klass, test_arguments)]487    def _make_tests(self, test_path, list_non_tests, subtests_filter=None):488        """489        Create test templates from given path490        :param test_path: File system path491        :param list_non_tests: include bad tests (NotATest, BrokenSymlink,...)492        :param subtests_filter: optional filter of methods for avocado tests493        """494        def ignore_broken(klass, uid, description=None):  # pylint: disable=W0613495            """Always return empty list"""496            return []497        if list_non_tests:  # return broken test with params498            make_broken = self._make_test499        else:  # return empty set instead500            make_broken = ignore_broken501        test_name = test_path502        if os.path.exists(test_path):503            if os.access(test_path, os.R_OK) is False:504                return make_broken(AccessDeniedPath, test_path, "Is not " "readable")505            return self._make_existing_file_tests(506                test_path, make_broken, subtests_filter507            )508        else:509            if os.path.islink(test_path):510                try:511                    if not os.path.isfile(os.readlink(test_path)):512                        return make_broken(513                            BrokenSymlink, test_path, "Is a " "broken symlink"514                        )515                except OSError:516                    return make_broken(517                        AccessDeniedPath, test_path, "Is not " "accessible."518                    )519            return self._make_nonexisting_file_tests(520                test_path, make_broken, subtests_filter, test_name521            )522    def _make_python_file_tests(523        self, test_path, make_broken, subtests_filter, test_name=None524    ):525        if test_name is None:526            test_name = test_path527        try:528            # Avocado tests529            avocado_tests, _ = safeloader.find_avocado_tests(test_path)530            if avocado_tests:531                test_factories = []532                for test_class, info in avocado_tests.items():533                    if isinstance(test_class, str):534                        for test_method, tags, _ in info:535                            name = test_name + f":{test_class}.{test_method}"536                            if subtests_filter and not subtests_filter.search(name):...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!!
