Пример #1
0
def get_run_dict_if_defined(testname):
    try:
        dict = ft_utils.get_dict_by_test(testname)
        if not dict:
            logger.error("Cannot get {}'s config options".format(testname))
        elif 'run' in dict:
            return dict['run']
        return None
    except Exception:
        logger.exception("Cannot get {}'s config options".format(testname))
        return None
Пример #2
0
 def get_run_dict(testname):
     """Obtain the the 'run' block of the testcase from testcases.yaml"""
     try:
         dic_testcase = ft_utils.get_dict_by_test(testname)
         if not dic_testcase:
             LOGGER.error("Cannot get %s's config options", testname)
         elif 'run' in dic_testcase:
             return dic_testcase['run']
         return None
     except Exception:  # pylint: disable=broad-except
         LOGGER.exception("Cannot get %s's config options", testname)
         return None
    def test_get_dict_by_test(self, mock_logger_error):
        with mock.patch('six.moves.builtins.open', mock.mock_open()), \
                mock.patch('functest.utils.functest_utils.yaml.safe_load') \
                as mock_yaml:
            mock_obj = mock.Mock()
            attrs = {'get.return_value': [{'testcases': [self.testcase_dict]}]}
            mock_obj.configure_mock(**attrs)

            mock_yaml.return_value = mock_obj

            self.assertDictEqual(
                functest_utils.get_dict_by_test(self.testname),
                self.testcase_dict)
Пример #4
0
    def run_test(self, test, tier_name, testcases=None):
        if not test.is_enabled():
            raise TestNotEnabled("The test case {} is not enabled".format(
                test.get_name()))
        logger.info("\n")  # blank line
        self.print_separator("=")
        logger.info("Running test case '%s'...", test.get_name())
        self.print_separator("=")
        logger.debug("\n%s" % test)
        self.source_rc_file()

        flags = " -t %s" % test.get_name()
        if self.report_flag:
            flags += " -r"

        result = testcase.TestCase.EX_RUN_ERROR
        run_dict = self.get_run_dict(test.get_name())
        if run_dict:
            try:
                module = importlib.import_module(run_dict['module'])
                cls = getattr(module, run_dict['class'])
                test_dict = ft_utils.get_dict_by_test(test.get_name())
                test_case = cls(**test_dict)
                self.executed_test_cases.append(test_case)
                if self.clean_flag:
                    if test_case.create_snapshot() != test_case.EX_OK:
                        return result
                try:
                    kwargs = run_dict['args']
                    result = test_case.run(**kwargs)
                except KeyError:
                    result = test_case.run()
                if result == testcase.TestCase.EX_OK:
                    if self.report_flag:
                        test_case.push_to_db()
                    result = test_case.is_successful()
                logger.info("Test result:\n\n%s\n", test_case)
                if self.clean_flag:
                    test_case.clean()
            except ImportError:
                logger.exception("Cannot import module {}".format(
                    run_dict['module']))
            except AttributeError:
                logger.exception("Cannot get class {}".format(
                    run_dict['class']))
        else:
            raise Exception("Cannot import the class for the test case.")

        return result
Пример #5
0
 def run_test(self, test):
     """Run one test case"""
     if not test.is_enabled():
         raise TestNotEnabled("The test case {} is not enabled".format(
             test.get_name()))
     LOGGER.info("Running test case '%s'...", test.get_name())
     result = testcase.TestCase.EX_RUN_ERROR
     run_dict = self.get_run_dict(test.get_name())
     if run_dict:
         try:
             module = importlib.import_module(run_dict['module'])
             cls = getattr(module, run_dict['class'])
             test_dict = ft_utils.get_dict_by_test(test.get_name())
             test_case = cls(**test_dict)
             self.executed_test_cases[test.get_name()] = test_case
             try:
                 kwargs = run_dict['args']
                 test_case.run(**kwargs)
             except KeyError:
                 test_case.run()
             if self.report_flag:
                 test_case.push_to_db()
             if test.get_project() == "functest":
                 result = test_case.is_successful()
             else:
                 result = testcase.TestCase.EX_OK
             LOGGER.info("Test result:\n\n%s\n", test_case)
             if self.clean_flag:
                 test_case.clean()
         except ImportError:
             LOGGER.exception("Cannot import module %s", run_dict['module'])
         except AttributeError:
             LOGGER.exception("Cannot get class %s", run_dict['class'])
     else:
         raise Exception("Cannot import the class for the test case.")
     return result