How to use find_python_tests method in avocado

Best Python code snippet using avocado_python

core.py

Source:core.py Github

copy

Full Screen

...251 disabled.update(_disabled)252 if _match is not match:253 match = _match254 return info, disabled, match255def find_python_tests(target_module, target_class, determine_match, path):256 """257 Attempts to find Python tests from source files258 A Python test in this context is a method within a specific type259 of class (or that inherits from a specific class).260 :param target_module: the name of the module from which a class should261 have come from. When attempting to find a Python262 unittest, the target_module will most probably263 be "unittest", as per the standard library module264 name. When attempting to find Avocado tests, the265 target_module will most probably be "avocado".266 :type target_module: str267 :param target_class: the name of the class that is considered to contain268 test methods. When attempting to find Python269 unittests, the target_class will most probably be270 "TestCase". When attempting to find Avocado tests,271 the target_class will most probably be "Test".272 :type target_class: str273 :type determine_match: a callable that will determine if a given module274 and class is contains valid Python tests275 :type determine_match: function276 :param path: path to a Python source code file277 :type path: str278 :returns: tuple where first item is dict with class name and additional279 info such as method names and tags; the second item is280 set of class names which look like Python tests but have been281 forcefully disabled.282 :rtype: tuple283 """284 module = PythonModule(path, target_module, target_class)285 # The resulting test classes286 result = collections.OrderedDict()287 disabled = set()288 for klass in module.iter_classes():289 docstring = ast.get_docstring(klass)290 # Looking for a class that has in the docstring either291 # ":avocado: enable" or ":avocado: disable292 if check_docstring_directive(docstring, "disable"):293 disabled.add(klass.name)294 continue295 if check_docstring_directive(docstring, "enable"):296 info = get_methods_info(297 klass.body,298 get_docstring_directives_tags(docstring),299 get_docstring_directives_dependencies(docstring),300 )301 result[klass.name] = info302 continue303 # From this point onwards we want to do recursive discovery, but304 # for now we don't know whether it is avocado.Test inherited305 # (Ifs are optimized for readability, not speed)306 # If "recursive" tag is specified, it is forced as test307 if check_docstring_directive(docstring, "recursive"):308 match = True309 else:310 match = module.is_matching_klass(klass)311 info = get_methods_info(312 klass.body,313 get_docstring_directives_tags(docstring),314 get_docstring_directives_dependencies(docstring),315 )316 # Getting the list of parents of the current class317 parents = klass.bases318 match = _examine_same_module(319 parents,320 info,321 disabled,322 match,323 module,324 target_module,325 target_class,326 determine_match,327 )328 # If there are parents left to be discovered, they329 # might be in a different module.330 for parent in parents:331 try:332 (333 parent_class,334 imported_symbol,335 symbol_is_module,336 ) = _get_attributes_for_further_examination(parent, module)337 found_spec = imported_symbol.get_importable_spec(symbol_is_module)338 if found_spec is None:339 continue340 except ClassNotSuitable:341 continue342 _info, _dis, _match = _examine_class(343 target_module,344 target_class,345 determine_match,346 found_spec.origin,347 parent_class,348 match,349 )350 if _info:351 info.extend(_info)352 disabled.update(_dis)353 if _match is not match:354 match = _match355 # Only update the results if this was detected as 'avocado.Test'356 if match:357 result[klass.name] = info358 return result, disabled359def _determine_match_python(module, klass, docstring):360 """361 Implements the match check for all Python based test classes362 Meaning that the enable/disabled/recursive tags are respected for363 Avocado Instrumented Tests and Python unittests.364 """365 directives = get_docstring_directives(docstring)366 if "disable" in directives:367 return False368 if "enable" in directives:369 return True370 if "recursive" in directives:371 return True372 # Still not decided, try inheritance373 return module.is_matching_klass(klass)374def find_avocado_tests(path):375 return find_python_tests("avocado", "Test", _determine_match_python, path)376def find_python_unittests(path):377 found, _ = find_python_tests("unittest", "TestCase", _determine_match_python, path)...

Full Screen

Full Screen

pythontestsprovider.py

Source:pythontestsprovider.py Github

copy

Full Screen

...19 return []20 includes = config.pop('include') or []21 excludes = config.pop('exclude') or []22 parameters = config.pop('parameters') or Configuration()23 all_tests = self.find_python_tests()24 PythonTestsProvider.validate_match_strings(all_tests,25 includes+excludes)26 # Instantiate tests selected27 for test in all_tests:28 test.selected = PythonTestsProvider.test_selected(test.name,29 includes, excludes)30 test_parameters_list = parameters.pop_raw(test.name)31 # If no parameters used, just create one empty set32 if test.selected and not test_parameters_list:33 test_parameters_list = [{}]34 if not isinstance(test_parameters_list, list):35 test_parameters_list = [test_parameters_list]36 for test_parameters in test_parameters_list:37 test.parameter_sets.append(test_parameters)38 parameters.ensure_consumed()39 config.ensure_consumed()40 return all_tests41 def find_python_tests(self):42 '''Search plugins module for classes inheriting TestBase and create TestDefinitions'''43 modules = {module_name: module44 for module_name, module in inspect.getmembers(pluma.plugins, inspect.ismodule)}45 submodules = {f'{module_name}.{submodule_name}': submodule46 for module_name, module in modules.items()47 for submodule_name, submodule in inspect.getmembers(module, inspect.ismodule)}48 test_classes = {}49 for module_name, module in {**modules, **submodules}.items():50 for class_name, cls in inspect.getmembers(module, inspect.isclass):51 # Exclude TestBase classes imported in but not defined in module52 if issubclass(cls, TestBase) and cls.__module__.startswith(module.__name__):53 full_name = f'{cls.__module__[cls.__module__.index(module_name):]}.{class_name}'54 test_classes[full_name] = cls55 all_tests = [TestDefinition(name=class_name, testclass=cls, test_provider=self)...

Full Screen

Full Screen

spider.py

Source:spider.py Github

copy

Full Screen

...35 repo=gh_repo.full_name))36 return len(list(results)) > 037 except GithubException:38 return False39def find_python_tests(gh_repo):40 if find_python_unittests(gh_repo):41 return True42 return False43TEST_FINDERS = {44 'ruby': find_ruby_tests,45 'python': find_python_tests,46}47def null_finder(gh_repo):48 return False49def tests_exist(lang, gh_repo):50 test_finder = TEST_FINDERS.get(lang.lower(), null_finder)51 return test_finder(gh_repo)52def check_for_tests(gh_repo, repo_model):53 for lang in repo_model.languages_by_usage():...

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