コード例 #1
0
ファイル: base.py プロジェクト: kelliott55/testplan
    def _run_case_related(self, method, testcase, resources, case_result):
        try:
            interface.check_signature(
                method, ["self", "name", "env", "result"]
            )
            method_args = (testcase.name, resources, case_result)
        except interface.MethodSignatureMismatch:
            interface.check_signature(
                method, ["self", "name", "env", "result", "kwargs"]
            )
            method_args = (
                testcase.name,
                resources,
                case_result,
                getattr(testcase, "_parametrization_kwargs", {}),
            )

        time_restriction = getattr(method, "timeout", None)
        if time_restriction:
            # pylint: disable=unbalanced-tuple-unpacking
            executed, execution_result = timing.timeout(
                time_restriction,
                f"`{method.__name__}` timeout after {{}} second(s)",
            )(method)(*method_args)
            if not executed:
                raise Exception(execution_result)
        else:
            method(*method_args)
コード例 #2
0
    def _run_testcase(self, testcase, pre_testcase, post_testcase):
        """Runs a testcase method and returns its report."""
        testcase_report = self._new_testcase_report(testcase)
        testcase_report.runtime_status = testplan.report.RuntimeStatus.RUNNING
        case_result = self.cfg.result(
            stdout_style=self.stdout_style, _scratch=self.scratch
        )

        with testcase_report.timer.record("run"):
            with testcase_report.logged_exceptions():
                if pre_testcase and callable(pre_testcase):
                    self._run_case_related(pre_testcase, testcase, case_result)

                time_restriction = getattr(testcase, "timeout", None)
                if time_restriction:
                    # pylint: disable=unbalanced-tuple-unpacking
                    executed, execution_result = timing.timeout(
                        time_restriction, "Testcase timeout after {} seconds"
                    )(testcase)(self.resources, case_result)
                    if not executed:
                        testcase_report.logger.error(execution_result)
                        testcase_report.status_override = (
                            testplan.report.Status.ERROR
                        )
                else:
                    testcase(self.resources, case_result)

                if post_testcase and callable(post_testcase):
                    self._run_case_related(
                        post_testcase, testcase, case_result
                    )

        # Apply testcase level summarization
        if getattr(testcase, "summarize", False):
            case_result.entries = [
                entries_base.Summary(
                    entries=case_result.entries,
                    num_passing=testcase.summarize_num_passing,
                    num_failing=testcase.summarize_num_failing,
                    key_combs_limit=testcase.summarize_key_combs_limit,
                )
            ]

        # native assertion objects -> dict form
        testcase_report.extend(case_result.serialized_entries)
        testcase_report.attachments.extend(case_result.attachments)

        # If xfailed testcase, force set status_override and update result
        if hasattr(testcase, "__xfail__"):
            testcase_report.xfail(testcase.__xfail__["strict"])

        testcase_report.pass_if_empty()
        testcase_report.runtime_status = testplan.report.RuntimeStatus.FINISHED

        if self.get_stdout_style(testcase_report.passed).display_testcase:
            self.log_testcase_status(testcase_report)

        return testcase_report
コード例 #3
0
ファイル: base.py プロジェクト: kelliott55/testplan
    def _run_suite_related(self, testsuite, method_name):
        """Runs testsuite related special methods setup/teardown/etc."""
        testsuite_method = getattr(testsuite, method_name, None)
        if testsuite_method is None:
            return None
        elif not callable(testsuite_method):
            raise TypeError("{} expected to be callable.".format(method_name))

        method_report = TestCaseReport(
            name=method_name, uid=method_name, suite_related=True
        )
        case_result = self.cfg.result(
            stdout_style=self.stdout_style, _scratch=self._scratch
        )

        try:
            interface.check_signature(
                testsuite_method, ["self", "env", "result"]
            )
            method_args = (self.resources, case_result)
        except interface.MethodSignatureMismatch:
            interface.check_signature(testsuite_method, ["self", "env"])
            method_args = (self.resources,)

        with method_report.timer.record("run"):
            with method_report.logged_exceptions():
                time_restriction = getattr(testsuite_method, "timeout", None)
                if time_restriction:
                    # pylint: disable=unbalanced-tuple-unpacking
                    executed, execution_result = timing.timeout(
                        time_restriction,
                        f"`{method_name}` timeout after {{}} second(s)",
                    )(testsuite_method)(*method_args)
                    if not executed:
                        method_report.logger.error(execution_result)
                        method_report.status_override = Status.ERROR
                else:
                    testsuite_method(*method_args)

        method_report.extend(case_result.serialized_entries)
        method_report.attachments.extend(case_result.attachments)
        method_report.pass_if_empty()
        method_report.runtime_status = RuntimeStatus.FINISHED

        return method_report
コード例 #4
0
ファイル: base.py プロジェクト: kelliott55/testplan
    def _run_testcase(
        self, testcase, pre_testcase, post_testcase, testcase_report=None
    ):
        """Runs a testcase method and returns its report."""
        testcase_report = testcase_report or self._new_testcase_report(
            testcase
        )
        case_result = self.cfg.result(
            stdout_style=self.stdout_style, _scratch=self.scratch
        )

        # as the runtime info currently has only testcase name we create it here
        # later can be moved out to multitest level, and cloned here as
        # testcases may run parallel

        runtime_info = MultiTestRuntimeInfo()
        runtime_info.testcase.name = testcase.name
        resources = RuntimeEnvironment(self.resources, runtime_info)

        with testcase_report.timer.record("run"):
            with testcase_report.logged_exceptions():
                if pre_testcase and callable(pre_testcase):
                    self._run_case_related(
                        pre_testcase, testcase, resources, case_result
                    )

                time_restriction = getattr(testcase, "timeout", None)
                if time_restriction:
                    # pylint: disable=unbalanced-tuple-unpacking
                    executed, execution_result = timing.timeout(
                        time_restriction,
                        f"`{testcase.name}` timeout after {{}} second(s)",
                    )(testcase)(resources, case_result)
                    if not executed:
                        testcase_report.logger.error(execution_result)
                        testcase_report.status_override = Status.ERROR
                else:
                    testcase(resources, case_result)

                if post_testcase and callable(post_testcase):
                    self._run_case_related(
                        post_testcase, testcase, resources, case_result
                    )

        # Apply testcase level summarization
        if getattr(testcase, "summarize", False):
            case_result.entries = [
                entries_base.Summary(
                    entries=case_result.entries,
                    num_passing=testcase.summarize_num_passing,
                    num_failing=testcase.summarize_num_failing,
                    key_combs_limit=testcase.summarize_key_combs_limit,
                )
            ]

        # native assertion objects -> dict form
        testcase_report.extend(case_result.serialized_entries)
        testcase_report.attachments.extend(case_result.attachments)

        # If xfailed testcase, force set status_override and update result
        if hasattr(testcase, "__xfail__"):
            testcase_report.xfail(testcase.__xfail__["strict"])

        testcase_report.pass_if_empty()
        testcase_report.runtime_status = RuntimeStatus.FINISHED

        if self.get_stdout_style(testcase_report.passed).display_testcase:
            self.log_testcase_status(testcase_report)

        return testcase_report