Exemplo n.º 1
0
    def run_tests(self):
        """Run PyUnit and wait for it to terminate."""
        suite_result = unittest.TestResult()
        self.cfg.suite.run(suite_result)

        for call, error in suite_result.errors:
            testcase_report = report_testing.TestCaseReport(name=str(call))
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))
            self.result.report.entries.append(testcase_report)

        for call, error in suite_result.failures:
            testcase_report = report_testing.TestCaseReport(name=str(call))
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))
            self.result.report.entries.append(testcase_report)

        # Since we only store testcases for errors or assertion failures,
        # we need to explicitly override the report status to be PASSED if
        # no errors/failures occured.
        if not self.result.report.entries:
            self.result.report.status_override = report_testing.Status.PASSED
Exemplo n.º 2
0
    def run_tests(self):
        """Run PyUnit and wait for it to terminate."""
        suite_result = unittest.TestResult()
        self.cfg.suite.run(suite_result)

        # Since we can't reliably inspect the individual testcases of a PyUnit
        # suite, we put all results into a single "testcase" report. This
        # will only list failures and errors and not give detail on individual
        # assertions like with MultiTest.
        testcase_report = report_testing.TestCaseReport(
            name=self._TESTCASE_NAME)

        for call, error in suite_result.errors:
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))

        for call, error in suite_result.failures:
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))

        # In case of no failures or errors we need to explicitly mark the
        # testsuite as passed.
        if not testcase_report.entries:
            log_entry = base_entries.Log("All PyUnit testcases passed",
                                         description="PyUnit success")
            testcase_report.append(schemas.base.registry.serialize(log_entry))

        self.result.report.append(testcase_report)
Exemplo n.º 3
0
    def dry_run(self):
        """Return an empty report tree."""
        report = self._new_test_report()
        testcase_report = report_testing.TestCaseReport(
            name=self._TESTCASE_NAME)
        report.append(testcase_report)

        return report
Exemplo n.º 4
0
    def run_tests(self):
        """Run PyUnit and wait for it to terminate."""
        suite_result = unittest.TestResult()
        self.cfg.suite.run(suite_result)

        for call, error in suite_result.errors:
            testcase_report = report_testing.TestCaseReport(name=str(call))
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))
            self.result.report.entries.append(testcase_report)

        for call, error in suite_result.failures:
            testcase_report = report_testing.TestCaseReport(name=str(call))
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))
            self.result.report.entries.append(testcase_report)
Exemplo n.º 5
0
    def _run_testsuite(self, pyunit_testcase):
        """Run a single PyUnit Testcase as a suite and return a testsuite report."""
        suite = unittest.defaultTestLoader.loadTestsFromTestCase(
            pyunit_testcase)
        suite_result = unittest.TextTestRunner().run(suite)

        # Since we can't reliably inspect the individual testcases of a PyUnit
        # suite, we put all results into a single "testcase" report. This
        # will only list failures and errors and not give detail on individual
        # assertions like with MultiTest.
        testcase_report = report_testing.TestCaseReport(
            name=self._TESTCASE_NAME, uid=self._TESTCASE_NAME)

        for call, error in suite_result.errors:
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))

        for call, error in suite_result.failures:
            assertion_obj = assertions.RawAssertion(description=str(call),
                                                    content=str(error).strip(),
                                                    passed=False)
            testcase_report.append(
                schemas.base.registry.serialize(assertion_obj))

        # In case of no failures or errors we need to explicitly mark the
        # testsuite as passed.
        if not testcase_report.entries:
            log_entry = base_entries.Log("All PyUnit testcases passed",
                                         description="PyUnit success")
            testcase_report.append(schemas.base.registry.serialize(log_entry))

        # We have to wrap the testcase report in a testsuite report.
        return report_testing.TestGroupReport(
            name=pyunit_testcase.__name__,
            uid=pyunit_testcase.__name__,
            category=report_testing.ReportCategories.TESTSUITE,
            entries=[testcase_report],
        )
Exemplo n.º 6
0
    def dry_run(self):
        """Return an empty report tree."""
        test_report = self._new_test_report()

        for pyunit_testcase in self.cfg.testcases:
            testsuite_report = report_testing.TestGroupReport(
                name=pyunit_testcase.__name__,
                uid=pyunit_testcase.__name__,
                category=report_testing.ReportCategories.TESTSUITE,
                entries=[
                    report_testing.TestCaseReport(
                        name=self._TESTCASE_NAME,
                        uid=self._TESTCASE_NAME,
                    )
                ],
            )
            test_report.append(testsuite_report)

        result = testing.TestResult()
        result.report = test_report

        return result