Best Python code snippet using avocado_python
list.py
Source:list.py
...103 else:104 test_matrix.append((type_label, params['name']))105 return test_matrix106 @staticmethod107 def _get_resolution_matrix(suite):108 """Used for resolver."""109 test_matrix = []110 verbose = suite.config.get('core.verbose')111 for test in suite.tests:112 runnable = test.runnable113 type_label = TERM_SUPPORT.healthy_str(runnable.kind)114 if verbose:115 tags_repr = []116 tags = runnable.tags or {}117 for tag, vals in tags.items():118 if vals:119 tags_repr.append("%s(%s)" % (tag,120 ",".join(vals)))121 else:122 tags_repr.append(tag)123 tags_repr = ",".join(tags_repr)124 test_matrix.append((type_label, runnable.uri, tags_repr))125 else:126 test_matrix.append((type_label, runnable.uri))127 return test_matrix128 @staticmethod129 def save_recipes(suite, directory, matrix_len):130 fmt = '%%0%uu.json' % len(str(matrix_len))131 index = 1132 for resolution in suite.resolutions:133 if resolution.result == ReferenceResolutionResult.SUCCESS:134 for res in resolution.resolutions:135 res.write_json(os.path.join(directory, fmt % index))136 index += 1137 def configure(self, parser):138 """139 Add the subparser for the list action.140 :param parser: The Avocado command line application parser141 :type parser: :class:`avocado.core.parser.ArgumentParser`142 """143 parser = super(List, self).configure(parser)144 help_msg = ('List of test references (aliases or paths). If empty, '145 'Avocado will list tests on the configured test source, '146 '(see "avocado config --datadir") Also, if there are '147 'other test loader plugins active, tests from those '148 'plugins might also show up (behavior may vary among '149 'plugins)')150 settings.register_option(section='list',151 key='references',152 default=[],153 nargs='*',154 key_type=list,155 help_msg=help_msg,156 parser=parser,157 positional_arg=True)158 loader.add_loader_options(parser, 'list')159 help_msg = ('What is the method used to detect tests? If --resolver '160 'used, Avocado will use the Next Runner Resolver method. '161 'If not the legacy one will be used.')162 settings.register_option(section='list',163 key='resolver',164 key_type=bool,165 default=False,166 help_msg=help_msg,167 parser=parser,168 long_arg='--resolver')169 help_msg = ('Writes runnable recipe files to a directory. Valid only '170 'when using --resolver.')171 settings.register_option(section='list.recipes',172 key='write_to_directory',173 default=None,174 metavar='DIRECTORY',175 help_msg=help_msg,176 parser=parser,177 long_arg='--write-recipes-to-directory')178 parser_common_args.add_tag_filter_args(parser)179 def run(self, config):180 runner = 'nrunner' if config.get('list.resolver') else 'runner'181 config['run.references'] = config.get('list.references')182 config['run.ignore_missing_references'] = True183 config['run.test_runner'] = runner184 try:185 suite = TestSuite.from_config(config)186 if runner == 'nrunner':187 matrix = self._get_resolution_matrix(suite)188 self._display(suite, matrix)189 directory = config.get('list.recipes.write_to_directory')190 if directory is not None:191 self.save_recipes(suite, directory, len(matrix))192 else:193 matrix = self._get_test_matrix(suite)194 self._display(suite, matrix)195 except KeyboardInterrupt:196 LOG_UI.error('Command interrupted by user...')...
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!!