Best Python code snippet using slash
loader.py
Source:loader.py  
...96            iterator = [thing]97        elif isinstance(thing, ResumedTestData):98            iterator = self._iter_test_resume(thing)99        elif not isinstance(thing, RunnableTestFactory):100            thing = self._get_runnable_test_factory(thing)101            iterator = thing.generate_tests(fixture_store=context.session.fixture_store)102        return (t for t in iterator if matcher is None or matcher.matches(t.__slash__))103    def _iter_test_resume(self, resume_state):104        for test in self._iter_path(resume_state.file_name):105            if self._is_excluded(test):106                continue107            if resume_state.address_in_file == test.__slash__.address_in_file:108                if resume_state.variation:109                    if not resume_state.variation == test.get_variation().id:110                        continue111                yield test112    def _iter_test_address(self, address):113        drive, address = os.path.splitdrive(address)114        if ':' in address:115            path, address_in_file = address.split(':', 1)116        else:117            path = address118            address_in_file = None119        path = os.path.join(drive, path)120        tests = list(self._iter_path(path))121        # special case for directories where we couldn't load any tests (without filter)122        if not tests and address_in_file is None:123            return124        matched = False125        for test in tests:126            if address_in_file is not None:127                if not self._address_in_file_matches(address_in_file, test):128                    continue129            matched = True130            if self._is_excluded(test):131                continue132            yield test133        if not matched:134            raise CannotLoadTests('Cannot find test(s) for {!r}'.format(address))135    def _address_in_file_matches(self, address_in_file, test):136        if address_in_file == test.__slash__.factory_name:137            return True138        test_address_in_file = test.__slash__.address_in_file139        if address_in_file == test_address_in_file:140            return True141        if '(' in test_address_in_file:142            if address_in_file == test_address_in_file[:test_address_in_file.index('(')]:143                return True144        return False145    def _iter_path(self, path):146        return self._iter_paths([path])147    def _iter_paths(self, paths):148        paths = list(paths)149        for path in paths:150            if not os.path.exists(path):151                msg = "Path {!r} could not be found".format(path)152                with handling_exceptions():153                    raise CannotLoadTests(msg)154        for path in paths:155            for file_path in _walk(path):156                _logger.debug("Checking {0}", file_path)157                if not self._is_file_wanted(file_path):158                    _logger.debug("{0} is not wanted. Skipping...", file_path)159                    continue160                module = None161                try:162                    with handling_exceptions(context="during import"):163                        if not config.root.run.message_assertion_introspection:164                            dessert.disable_message_introspection()165                        with dessert.rewrite_assertions_context():166                            module = import_file(file_path)167                except Exception as e:168                    tb_file, tb_lineno, _, _ = _extract_tb()169                    raise mark_exception_handled(170                        CannotLoadTests(171                            "Could not load {0!r} ({1}:{2} - {3})".format(file_path, tb_file, tb_lineno, e)))172                if module is not None:173                    self._duplicate_funcs |= check_duplicate_functions(file_path)174                    with self._adding_local_fixtures(file_path, module):175                        for runnable in self._iter_runnable_tests_in_module(file_path, module):176                            yield runnable177    @contextmanager178    def _adding_local_fixtures(self, file_path, module):179        with context.session.fixture_store.new_namespace_context():180            self._local_config.push_path(os.path.dirname(file_path))181            try:182                context.session.fixture_store.add_fixtures_from_dict(183                    self._local_config.get_dict())184                with context.session.fixture_store.new_namespace_context():185                    context.session.fixture_store.add_fixtures_from_dict(186                        vars(module))187                    context.session.fixture_store.resolve()188                    yield189            finally:190                self._local_config.pop_path()191    def _is_excluded(self, test):192        matchers = self._get_matchers()193        if matchers is None:194            return False195        return not all(m.matches(test.__slash__) for m in matchers)196    def _is_file_wanted(self, filename):197        return filename.endswith(".py")198    def _iter_runnable_tests_in_module(self, file_path, module):199        for thing_name in sorted(dir(module)):200            thing = getattr(module, thing_name)201            if thing is RunnableTestFactory:  # probably imported directly202                continue203            factory = self._get_runnable_test_factory(thing)204            if factory is None:205                continue206            factory.set_factory_name(thing_name)207            factory.set_module_name(module.__name__)208            factory.set_filename(file_path)209            for test in factory.generate_tests(fixture_store=context.session.fixture_store):210                assert test.__slash__ is not None211                yield test212    def _get_runnable_test_factory(self, thing):213        if isinstance(thing, type) and issubclass(thing, Test):214            return TestTestFactory(thing)215        if isinstance(thing, FunctionType):216            if is_valid_test_name(thing.__name__):217                return FunctionTestFactory(thing)218        return None219def _walk(p):220    if os.path.isfile(p):221        yield p222        return223    for path, dirnames, filenames in os.walk(p):224        dirnames[:] = sorted(dirname for dirname in dirnames if not dirname.startswith('.'))225        for filename in sorted(filenames):226            yield os.path.join(path, filename)...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!!
