How to use get_full_decorator_mapping method in avocado

Best Python code snippet using avocado_python

loader.py

Source:loader.py Github

copy

Full Screen

...150 for plugin in self._initialized_plugins:151 self._label_mapping.update(plugin.get_full_type_label_mapping())152 self._decorator_mapping = {MissingTest: output.TERM_SUPPORT.fail_header_str}153 for plugin in self._initialized_plugins:154 self._decorator_mapping.update(plugin.get_full_decorator_mapping())155 def get_extra_listing(self):156 for loader_plugin in self._initialized_plugins:157 loader_plugin.get_extra_listing()158 def get_base_keywords(self):159 base_path = []160 for loader_plugin in self._initialized_plugins:161 base_path += loader_plugin.get_base_keywords()162 return base_path163 def get_type_label_mapping(self):164 if self._label_mapping is None:165 raise RuntimeError(166 "LoaderProxy.discover has to be called before "167 "LoaderProxy.get_type_label_mapping"168 )169 return self._label_mapping170 def get_decorator_mapping(self):171 if self._label_mapping is None:172 raise RuntimeError(173 "LoaderProxy.discover has to be called before "174 "LoaderProxy.get_decorator_mapping"175 )176 return self._decorator_mapping177 def discover(self, references, which_tests=DiscoverMode.DEFAULT, force=None):178 """179 Discover (possible) tests from test references.180 :param references: a list of tests references; if [] use plugin defaults181 :type references: builtin.list182 :param which_tests: Limit tests to be displayed183 :type which_tests: :class:`DiscoverMode`184 :param force: don't raise an exception when some test references185 are not resolved to tests.186 :return: A list of test factories (tuples (TestClass, test_params))187 """188 def handle_exception(plugin, details):189 # FIXME: Introduce avocado.exceptions logger and use here190 stacktrace.log_message(191 (f"Test discovery plugin {plugin} " f"failed: {details}"),192 LOG_UI.getChild("exceptions"),193 )194 # FIXME: Introduce avocado.traceback logger and use here195 stacktrace.log_exc_info(sys.exc_info(), LOG_UI.getChild("debug"))196 tests = []197 unhandled_references = []198 if not references:199 for loader_plugin in self._initialized_plugins:200 try:201 tests.extend(loader_plugin.discover(None, which_tests))202 except Exception as details: # pylint: disable=W0703203 handle_exception(loader_plugin, details)204 else:205 for reference in references:206 handled = False207 for loader_plugin in self._initialized_plugins:208 try:209 _test = loader_plugin.discover(reference, which_tests)210 if _test:211 tests.extend(_test)212 handled = True213 if which_tests != DiscoverMode.ALL:214 break # Don't process other plugins215 except Exception as details: # pylint: disable=W0703216 handle_exception(loader_plugin, details)217 if not handled:218 unhandled_references.append(reference)219 if unhandled_references:220 if which_tests == DiscoverMode.ALL:221 tests.extend(222 [223 (MissingTest, {"name": reference})224 for reference in unhandled_references225 ]226 )227 else:228 # This is a workaround to avoid changing the method signature229 if force is True or force == "on":230 LOG_UI.error(231 LoaderUnhandledReferenceError(232 unhandled_references, self._initialized_plugins233 )234 )235 else:236 raise LoaderUnhandledReferenceError(237 unhandled_references, self._initialized_plugins238 )239 self._update_mappings()240 return tests241 def clear_plugins(self):242 self.registered_plugins = []243class TestLoader:244 """245 Base for test loader classes246 """247 name = None # Human friendly name of the loader248 def __init__(self, config, extra_params): # pylint: disable=W0613249 if "allowed_test_types" in extra_params:250 mapping = self.get_type_label_mapping()251 types = extra_params.pop("allowed_test_types")252 if len(mapping) != 1:253 msg = (254 f"Loader '{self.name}' supports multiple test types "255 f"but does not handle the 'allowed_test_types'. "256 f"Either don't use '{self.name}' instead of "257 f"'{self.name}.{types}' or take care of the "258 f"'allowed_test_types' in the plugin."259 )260 raise LoaderError(msg)261 elif next(iter(mapping.values())) != types:262 raise LoaderError(263 f"Loader '{self.name}' doesn't support "264 f"test type '{types}', it supports only "265 f"'{next(iter(mapping.values()))}'"266 )267 if "loader_options" in extra_params:268 raise LoaderError(269 f"Loader '{self.name}' doesn't support "270 f"'loader_options', please don't use "271 f"--loader {self.name}:"272 f"{extra_params.get('loader_options')}"273 )274 if extra_params:275 raise LoaderError(276 f"Loader '{self.name}' doesn't handle extra "277 f"params {extra_params}, please adjust your "278 f"plugin to take care of them."279 )280 self.config = config281 def get_extra_listing(self):282 pass283 @staticmethod284 def get_type_label_mapping():285 """286 Get label mapping for display in test listing.287 :return: Dict {TestClass: 'TEST_LABEL_STRING'}288 """289 raise NotImplementedError290 def get_full_type_label_mapping(self): # pylint: disable=R0201291 """292 Allows extending the type-label-mapping after the object is initialized293 """294 return self.get_type_label_mapping()295 @staticmethod296 def get_decorator_mapping():297 """298 Get label mapping for display in test listing.299 :return: Dict {TestClass: decorator function}300 """301 raise NotImplementedError302 def get_full_decorator_mapping(self): # pylint: disable=R0201303 """304 Allows extending the decorator-mapping after the object is initialized305 """306 return self.get_decorator_mapping()307 def discover(self, reference, which_tests=DiscoverMode.DEFAULT):308 """309 Discover (possible) tests from an reference.310 :param reference: the reference to be inspected.311 :type reference: str312 :param which_tests: Limit tests to be displayed313 :type which_tests: :class:`DiscoverMode`314 :return: a list of test matching the reference as params.315 """316 raise NotImplementedError...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...39 return self._extra_type_label_mapping40 @staticmethod41 def get_decorator_mapping():42 return {}43 def get_full_decorator_mapping(self):44 return self._extra_decorator_mapping45 def _get_loader(self, params):46 """47 Initializes test loader according to params.48 Uses params.get():49 test_reference_resolver_class - loadable location of the loader class50 test_reference_resolver_args - args to override current Avocado args51 before being passed to the loader52 class. (dict)53 test_reference_resolver_extra - extra_params to be passed to resolver54 (dict)55 """56 resolver_class = params.get("test_reference_resolver_class")57 if not resolver_class:58 if params.get("test_reference"):59 resolver_class = "avocado.core.loader.FileLoader"60 else:61 # Don't supply the default when no `test_reference` is given62 # to avoid listing default FileLoader tests63 return None64 mod, klass = resolver_class.rsplit(".", 1)65 try:66 loader_class = getattr(__import__(mod, fromlist=[klass]), klass)67 except ImportError:68 raise RuntimeError("Unable to import class defined by test_"69 "reference_resolver_class '%s.%s'"70 % (mod, klass))71 _args = params.get("test_reference_resolver_args")72 if not _args:73 args = self.args74 else:75 args = copy.copy(self.args)76 for key, value in iteritems(_args):77 setattr(args, key, value)78 extra_params = params.get("test_reference_resolver_extra", default={})79 if extra_params:80 extra_params = copy.deepcopy(extra_params)81 return loader_class(args, extra_params)82 def discover(self, reference, which_tests=loader.DiscoverMode.DEFAULT):83 tests = []84 try:85 root = mux.apply_filters(create_from_yaml([reference], False),86 getattr(self.args, "mux_suite_only", []),87 getattr(self.args, "mux_suite_out", []))88 except Exception:89 return []90 mux_tree = mux.MuxTree(root)91 for variant in mux_tree:92 params = parameters.AvocadoParams(variant, ["/run/*"],93 output.LOG_JOB.name)94 references = params.get("test_reference")95 if not isinstance(references, (list, tuple)):96 references = [references]97 for reference in references:98 test_loader = self._get_loader(params)99 if not test_loader:100 continue101 _tests = test_loader.discover(reference, which_tests)102 self._extra_type_label_mapping.update(103 test_loader.get_full_type_label_mapping())104 self._extra_decorator_mapping.update(105 test_loader.get_full_decorator_mapping())106 name_prefix = params.get("mux_suite_test_name_prefix")107 if _tests:108 if isinstance(name_prefix, list):109 name_prefix = "".join(name_prefix)110 for tst in _tests:111 if name_prefix:112 tst[1]["name"] = name_prefix + tst[1]["name"]113 tst[1]["params"] = (variant, ["/run/*"])114 tests.extend(_tests)115 return tests116class LoaderYAML(CLI):117 name = 'loader_yaml'118 description = "YAML test loader options for the 'run' subcommand"119 def configure(self, parser):...

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 avocado 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