How to use the gabbi.fixture function in gabbi

To help you get started, we’ve selected a few gabbi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cdent / gabbi / gabbi / test_intercept.py View on Github external
def preprocess(self, test):
        """Add some data if the data is a string."""
        try:
            test.output = test.output + '\nAnother line'
        except TypeError:
            pass

    def action(self, test, expected, value=None):
        expected = expected.replace('COW', '', 1)
        test.assertIn(expected, test.output)


# Incorporate the SkipAllFixture into this namespace so it can be used
# by tests (cf. skipall.yaml).
SkipAllFixture = fixture.SkipAllFixture


def load_tests(loader, tests, pattern):
    """Provide a TestSuite to the discovery process."""
    # Set and environment variable for one of the tests.
    os.environ['GABBI_TEST_URL'] = 'takingnames'
    prefix = os.environ.get('GABBI_PREFIX')
    test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
    return driver.build_tests(test_dir, loader, host=None,
                              intercept=simple_wsgi.SimpleWsgi,
                              prefix=prefix,
                              fixture_module=sys.modules[__name__],
                              response_handlers=[TestResponseHandler])
github cdent / gabbi / gabbi / suite.py View on Github external
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