def _run_teardown(self, context): if not self.teardown: return teardown = Teardown(self.teardown.name, self.teardown.args) teardown.replace_variables(context.get_current_vars(), []) context.start_teardown() run_errors = KeywordRunErrors() teardown.run(context, KeywordTeardownListener(run_errors)) context.end_teardown() return run_errors.teardown_error
def __init__(self, data, parent=None, defaults=None): BaseTestSuite.__init__(self, data.name, data.source, parent) self.variables = GLOBAL_VARIABLES.copy() self.variables.set_from_variable_table(data.variable_table) self.source = data.source self.doc = data.setting_table.doc.value self.metadata = self._get_metadata(data.setting_table.metadata) self.imports = data.imports self.user_keywords = UserLibrary(data.keywords) self.setup = Setup(data.setting_table.suite_setup.name, data.setting_table.suite_setup.args) self.teardown = Teardown(data.setting_table.suite_teardown.name, data.setting_table.suite_teardown.args) defaults = DefaultValues(data.setting_table, defaults) for suite in data.children: RunnableTestSuite(suite, parent=self, defaults=defaults) for test in data.testcase_table: RunnableTestCase(test, parent=self, defaults=defaults) self._run_mode_exit_on_failure = False self._run_mode_dry_run = False self._run_mode_skip_teardowns_on_exit = False
def __init__(self, suitedatas): BaseTestSuite.__init__(self, name='') self.variables = GLOBAL_VARIABLES.copy() self.doc = '' self.imports = [] self.setup = Setup(None, None) self.teardown = Teardown(None, None) for suite in suitedatas: RunnableTestSuite(suite, parent=self) self._run_mode_exit_on_failure = False self._run_mode_dry_run = False self._run_mode_skip_teardowns_on_exit = False
def get_teardown(self, tc_teardown): td = tc_teardown if tc_teardown.is_set( ) else self._get_default_teardown() return Teardown(td.name, td.args)
class RunnableTestSuite(BaseTestSuite): def __init__(self, data, parent=None, defaults=None): BaseTestSuite.__init__(self, data.name, data.source, parent) self.variables = GLOBAL_VARIABLES.copy() self.variables.set_from_variable_table(data.variable_table) self.source = data.source self.doc = data.setting_table.doc.value self.metadata = self._get_metadata(data.setting_table.metadata) self.imports = data.imports self.user_keywords = UserLibrary(data.keywords) self.setup = Setup(data.setting_table.suite_setup.name, data.setting_table.suite_setup.args) self.teardown = Teardown(data.setting_table.suite_teardown.name, data.setting_table.suite_teardown.args) defaults = DefaultValues(data.setting_table, defaults) for suite in data.children: RunnableTestSuite(suite, parent=self, defaults=defaults) for test in data.testcase_table: RunnableTestCase(test, parent=self, defaults=defaults) self._run_mode_exit_on_failure = False self._run_mode_dry_run = False self._run_mode_skip_teardowns_on_exit = False def filter_empty_suites(self): for suite in self.suites[:]: suite.filter_empty_suites() if suite.get_test_count() == 0: self.suites.remove(suite) LOGGER.info("Running test suite '%s' failed: Test suite" " contains no test cases." % (suite.source)) def _get_metadata(self, metadata): meta = utils.NormalizedDict() for item in metadata: meta[item.name] = item.value return meta def run(self, output, parent=None, errors=None): context = self._start_run(output, parent, errors) self._run_setup(context) self._run_sub_suites(context) self._run_tests(context) self._report_status(context) self._run_teardown(context) self._end_run(context) def _start_run(self, output, parent, errors): if not errors: errors = SuiteRunErrors(self._run_mode_exit_on_failure, self._run_mode_skip_teardowns_on_exit) self.run_errors = errors self.run_errors.start_suite() self.status = 'RUNNING' self.starttime = utils.get_timestamp() parent_vars = parent.context.get_current_vars() if parent else None self.context = ExecutionContext(Namespace(self, parent_vars), output, self._run_mode_dry_run) self._set_variable_dependent_metadata(self.context) output.start_suite(self) return self.context def _set_variable_dependent_metadata(self, context): errors = [] self.doc = context.replace_vars_from_setting('Documentation', self.doc, errors) self.setup.replace_variables(context.get_current_vars(), errors) self.teardown.replace_variables(context.get_current_vars(), errors) for name, value in self.metadata.items(): self.metadata[name] = context.replace_vars_from_setting(name, value, errors) if errors: self.run_errors.suite_init_err('Suite initialization failed:\n%s' % '\n'.join(errors)) def _run_setup(self, context): if self.run_errors.is_suite_setup_allowed(): self.setup.run(context, SuiteSetupListener(self)) self.run_errors.setup_executed() def _run_teardown(self, context): if self.run_errors.is_suite_teardown_allowed(): self.teardown.run(context, SuiteTearDownListener(self)) def _run_sub_suites(self, context): for suite in self.suites: suite.run(context.output, self, self.run_errors) def _run_tests(self, context): executed_tests = [] for test in self.tests: normname = utils.normalize(test.name) if normname in executed_tests: LOGGER.warn("Multiple test cases with name '%s' executed in " "test suite '%s'"% (test.name, self.longname)) executed_tests.append(normname) test.run(context, self.run_errors) context.set_prev_test_variables(test) def _report_status(self, context): self.set_status() self.message = self.run_errors.suite_error() context.report_suite_status(self.status, self.get_full_message()) def _end_run(self, context): self.endtime = utils.get_timestamp() self.elapsedtime = utils.get_elapsed_time(self.starttime, self.endtime) context.copy_prev_test_vars_to_global() context.end_suite(self) self.run_errors.end_suite()
class RunnableTestSuite(BaseTestSuite): def __init__(self, data, parent=None, defaults=None): BaseTestSuite.__init__(self, data.name, data.source, parent) self.variables = GLOBAL_VARIABLES.copy() self.variables.set_from_variable_table(data.variable_table) self.source = data.source self.doc = data.setting_table.doc.value self.metadata = self._get_metadata(data.setting_table.metadata) self.imports = data.imports self.user_keywords = UserLibrary(data.keywords) self.setup = Setup(data.setting_table.suite_setup.name, data.setting_table.suite_setup.args) self.teardown = Teardown(data.setting_table.suite_teardown.name, data.setting_table.suite_teardown.args) defaults = DefaultValues(data.setting_table, defaults) for suite in data.children: RunnableTestSuite(suite, parent=self, defaults=defaults) for test in data.testcase_table: RunnableTestCase(test, parent=self, defaults=defaults) self._run_mode_exit_on_failure = False self._run_mode_dry_run = False self._run_mode_skip_teardowns_on_exit = False def filter_empty_suites(self): for suite in self.suites[:]: suite.filter_empty_suites() if suite.get_test_count() == 0: self.suites.remove(suite) LOGGER.info("Running test suite '%s' failed: Test suite" " contains no test cases." % (suite.source)) def _get_metadata(self, metadata): meta = utils.NormalizedDict() for item in metadata: meta[item.name] = item.value return meta def run(self, output, parent=None, errors=None): context = self._start_run(output, parent, errors) self._run_setup(context) self._run_sub_suites(context) self._run_tests(context) self._report_status(context) self._run_teardown(context) self._end_run(context) def _start_run(self, output, parent, errors): if not errors: errors = SuiteRunErrors(self._run_mode_exit_on_failure, self._run_mode_skip_teardowns_on_exit) self.run_errors = errors self.run_errors.start_suite() self.status = 'RUNNING' self.starttime = utils.get_timestamp() parent_vars = parent.context.get_current_vars() if parent else None self.context = ExecutionContext(Namespace(self, parent_vars), output, self._run_mode_dry_run) self._set_variable_dependent_metadata(self.context) output.start_suite(self) return self.context def _set_variable_dependent_metadata(self, context): errors = [] self.doc = context.replace_vars_from_setting('Documentation', self.doc, errors) self.setup.replace_variables(context.get_current_vars(), errors) self.teardown.replace_variables(context.get_current_vars(), errors) for name, value in self.metadata.items(): self.metadata[name] = context.replace_vars_from_setting( name, value, errors) if errors: self.run_errors.suite_init_err('Suite initialization failed:\n%s' % '\n'.join(errors)) def _run_setup(self, context): if self.run_errors.is_suite_setup_allowed(): self.setup.run(context, SuiteSetupListener(self)) self.run_errors.setup_executed() def _run_teardown(self, context): if self.run_errors.is_suite_teardown_allowed(): self.teardown.run(context, SuiteTearDownListener(self)) def _run_sub_suites(self, context): for suite in self.suites: suite.run(context.output, self, self.run_errors) def _run_tests(self, context): executed_tests = [] for test in self.tests: normname = utils.normalize(test.name) if normname in executed_tests: LOGGER.warn("Multiple test cases with name '%s' executed in " "test suite '%s'" % (test.name, self.longname)) executed_tests.append(normname) test.run(context, self.run_errors) context.set_prev_test_variables(test) def _report_status(self, context): self.set_status() self.message = self.run_errors.suite_error() context.report_suite_status(self.status, self.get_full_message()) def _end_run(self, context): self.endtime = utils.get_timestamp() self.elapsedtime = utils.get_elapsed_time(self.starttime, self.endtime) context.copy_prev_test_vars_to_global() context.end_suite(self) self.run_errors.end_suite()