Ejemplo n.º 1
0
    def run(self, result, debug=False):
        """Override TestSuite run to start suite-level fixtures.

        To avoid exception confusion, use a null Fixture when there
        are no fixtures.
        """

        fixtures, intercept, host, port, prefix = self._get_intercept()

        try:
            with fixture.nest([fix() for fix in fixtures]):
                if intercept:
                    with interceptor.Urllib3Interceptor(
                            intercept, host, port, prefix):
                        result = super(GabbiSuite, self).run(result, debug)
                else:
                    result = super(GabbiSuite, self).run(result, debug)
        except unittest.SkipTest as exc:
            for test in self._tests:
                result.addSkip(test, str(exc))
        # If we have an exception in the nested fixtures, that means
        # there's been an exception somewhere in the cycle other
        # than a specific test (as that would have been caught
        # already), thus from a fixture. If that exception were to
        # continue to raise here, then some test runners would
        # swallow it and the traceback of the failure would be
        # undiscoverable. To ensure the traceback is reported (via
        # the testrunner) to a human, the first test in the suite is
        # marked as having an error (it's fixture failed) and then
        # the entire suite is skipped, and the result stream told
        # we're done. If there are no tests (an empty suite) the
        # exception is re-raised.
        except Exception as exc:
            if self._tests:
                result.addError(self._tests[0], sys.exc_info())
                for test in self._tests:
                    result.addSkip(test, 'fixture failure')
                result.stop()
            else:
                raise

        return result
Ejemplo n.º 2
0
    def start(self, result):
        """Start fixtures when using pytest."""
        fixtures, intercept, host, port, prefix = self._get_intercept()

        self.used_fixtures = []
        try:
            for fix in fixtures:
                fix_object = fix()
                fix_object.__enter__()
                self.used_fixtures.append(fix_object)
        except unittest.SkipTest as exc:
            # Disable the already collected tests that we now wish
            # to skip.
            for test in self:
                test.run = noop
                result.addSkip(test, str(exc))
            result.addSkip(self, str(exc))
        if intercept:
            intercept_fixture = interceptor.Urllib3Interceptor(
                intercept, host, port, prefix)
            intercept_fixture.__enter__()
            self.used_fixtures.append(intercept_fixture)
Ejemplo n.º 3
0
    def run(self, result, debug=False):
        """Override TestSuite run to start suite-level fixtures.

        To avoid exception confusion, use a null Fixture when there
        are no fixtures.
        """

        fixtures, intercept, host, port, prefix = self._get_intercept()

        try:
            with fixture.nest([fix() for fix in fixtures]):
                if intercept:
                    with interceptor.Urllib3Interceptor(
                            intercept, host, port, prefix):
                        result = super(GabbiSuite, self).run(result, debug)
                else:
                    result = super(GabbiSuite, self).run(result, debug)
        except unittest.SkipTest as exc:
            for test in self._tests:
                result.addSkip(test, str(exc))

        return result