How to use _make_existing_file_tests method in avocado

Best Python code snippet using avocado_python

loader.py

Source:loader.py Github

copy

Full Screen

...556 # Module does not have an avocado test class inside, and557 # it's not executable. Not a Test.558 return make_broken(NotATest, test_path,559 self.__not_test_str)560 def _make_existing_file_tests(self, test_path, make_broken,561 subtests_filter, test_name=None):562 if test_name is None:563 test_name = test_path564 try:565 # Avocado tests566 avocado_tests, disabled = safeloader.find_avocado_tests(test_path)567 if avocado_tests:568 test_factories = []569 for test_class, info in avocado_tests.items():570 if isinstance(test_class, string_types):571 for test_method, tags in info:572 name = test_name + \573 ':%s.%s' % (test_class, test_method)574 if (subtests_filter and575 not subtests_filter.search(name)):576 continue577 tst = (test_class, {'name': name,578 'modulePath': test_path,579 'methodName': test_method,580 'tags': tags})581 test_factories.append(tst)582 return test_factories583 # Python unittests584 old_dir = os.getcwd()585 try:586 py_test_dir = os.path.abspath(os.path.dirname(test_path))587 py_test_name = os.path.basename(test_path)588 os.chdir(py_test_dir)589 python_unittests = self._find_python_unittests(py_test_name,590 disabled,591 subtests_filter)592 finally:593 os.chdir(old_dir)594 if python_unittests:595 return [(test.PythonUnittest, {"name": name,596 "test_dir": py_test_dir})597 for name in python_unittests]598 else:599 return self._make_simple_or_broken_test(test_path,600 subtests_filter,601 make_broken)602 # Since a lot of things can happen here, the broad exception is603 # justified. The user will get it unadulterated anyway, and avocado604 # will not crash.605 except BaseException as details: # Ugly python files can raise any exc606 if isinstance(details, KeyboardInterrupt):607 raise # Don't ignore ctrl+c608 else:609 return self._make_simple_or_broken_test(test_path,610 subtests_filter)611 @staticmethod612 def _make_test(klass, uid, description=None, subtests_filter=None,613 **test_arguments):614 """615 Create test template616 :param klass: test class617 :param uid: test uid (by default used as id and name)618 :param description: Description appended to "uid" (for listing purpose)619 :param subtests_filter: optional filter of methods for avocado tests620 :param test_arguments: arguments to be passed to the klass(test_arguments)621 """622 if subtests_filter and not subtests_filter.search(uid):623 return []624 if description:625 uid = "%s: %s" % (uid, description)626 test_arguments["name"] = uid627 return [(klass, test_arguments)]628 def _make_tests(self, test_path, list_non_tests, subtests_filter=None):629 """630 Create test templates from given path631 :param test_path: File system path632 :param list_non_tests: include bad tests (NotATest, BrokenSymlink,...)633 :param subtests_filter: optional filter of methods for avocado tests634 """635 def ignore_broken(klass, uid, description=None): # pylint: disable=W0613636 """ Always return empty list """637 return []638 if list_non_tests: # return broken test with params639 make_broken = self._make_test640 else: # return empty set instead641 make_broken = ignore_broken642 test_name = test_path643 if os.path.exists(test_path):644 if os.access(test_path, os.R_OK) is False:645 return make_broken(AccessDeniedPath, test_path, "Is not "646 "readable")647 if test_path.endswith('.py'):648 return self._make_existing_file_tests(test_path, make_broken,649 subtests_filter)650 else:651 if os.access(test_path, os.X_OK):652 return self._make_test(test.SimpleTest, test_path,653 subtests_filter=subtests_filter,654 executable=test_path)655 else:656 return make_broken(NotATest, test_path,657 self.__not_test_str)658 else:659 if os.path.islink(test_path):660 try:661 if not os.path.isfile(os.readlink(test_path)):662 return make_broken(BrokenSymlink, test_path, "Is a "663 "broken symlink")664 except OSError:665 return make_broken(AccessDeniedPath, test_path, "Is not "666 "accessible.")667 # Try to resolve test ID (keep compatibility)668 test_path = os.path.join(data_dir.get_test_dir(), test_name)669 if os.path.exists(test_path):670 return self._make_existing_file_tests(test_path, make_broken,671 subtests_filter,672 test_name)673 else:674 if not subtests_filter and ':' in test_name:675 test_name, subtests_filter = test_name.split(':', 1)676 test_path = os.path.join(data_dir.get_test_dir(),677 test_name)678 if os.path.exists(test_path):679 subtests_filter = re.compile(subtests_filter)680 return self._make_existing_file_tests(test_path,681 make_broken,682 subtests_filter,683 test_name)684 return make_broken(NotATest, test_name, "File not found "685 "('%s'; '%s')" % (test_name, test_path))686 return make_broken(NotATest, test_name, self.__not_test_str)687class ExternalLoader(TestLoader):688 """689 External-runner loader class690 """691 name = 'external'692 def __init__(self, args, extra_params):693 loader_options = extra_params.pop('loader_options', None)694 super(ExternalLoader, self).__init__(args, extra_params)...

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