gabbi Package

case Module

A single HTTP request represented as a subclass of unittest.TestCase

The test case encapsulates the request headers and body and expected response headers and body. When the test is run an HTTP request is made using httplib2. Assertions are made against the reponse.

class gabbi.case.HTTPTestCase(*args, **kwargs)

Bases: testtools.testcase.TestCase

Encapsulate a single HTTP request as a TestCase.

If the test is a member of a sequence of requests, ensure that prior tests are run.

To keep the test harness happy we need to make sure the setUp and tearDown are only run once.

replace_template(message)

Replace magic strings in message.

setUp()
tearDown()
test_request()

Run this request if it has not yet run.

If there is a prior test in the sequence, run it first.

exception gabbi.case.ServerError

Bases: exceptions.Exception

A catchall ServerError.

gabbi.case.potentialFailure(func)

Decorate a test method that is expected to fail if ‘xfail’ is true.

driver Module

Generate HTTP tests from YAML files

Each HTTP request is its own TestCase and can be requested to be run in isolation from other tests. If it is member of a sequence of requests, prior requests will be run.

A sequence is represented by an ordered list in a single YAML file.

Each sequence becomes a TestSuite.

An entire directory of YAML files is a TestSuite of TestSuites.

class gabbi.driver.TestBuilder

Bases: type

Metaclass to munge a dynamically created test.

required_attributes = {'has_run': False}
gabbi.driver.build_tests(path, loader, host=None, port=8001, intercept=None, test_loader_name=None, fixture_module=None)

Read YAML files from a directory to create tests.

Each YAML file represents an ordered sequence of HTTP requests.

gabbi.driver.load_yaml(yaml_file)

Read and parse any YAML file. Let exceptions flow where they may.

gabbi.driver.test_suite_from_yaml(loader, test_base_name, test_yaml, test_directory, host, port, fixture_module, intercept)

Generate a TestSuite from YAML data.

fixture Module

Manage fixtures for gabbi at the test suite level.

class gabbi.fixture.GabbiFixture

Bases: object

A context manager that operates as a fixture.

Subclasses must implement start_fixture and stop_fixture, each of which contain the logic for stopping and starting whatever the fixture is. What a fixture is is left as an exercise for the implementor.

These context managers will be nested so any actually work needs to happen in start_fixture and stop_fixture and not in __init__. Otherwise exception handling will not work properly.

start_fixture()

Implement the actual workings of starting the fixture here.

stop_fixture()

Implement the actual workings of stopping the fixture here.

exception gabbi.fixture.GabbiFixtureError

Bases: exceptions.Exception

Generic exception for GabbiFixture.

class gabbi.fixture.InterceptFixture(host, port, app)

Bases: gabbi.fixture.GabbiFixture

Start up the wsgi intercept. This should not be called directly.

start_fixture()
stop_fixture()
class gabbi.fixture.SkipAllFixture

Bases: gabbi.fixture.GabbiFixture

A fixture that skips all the tests in the current suite.

start_fixture()
gabbi.fixture.nest(*args, **kwds)

Nest a series of fixtures.

This is duplicated from nested in the stdlib, which has been deprecated because of issues with how exceptions are difficult to handle during __init__. Gabbi needs to nest an unknown number of fixtures dynamically, so the with syntax that replaces nested will not work.

suite Module

A TestSuite for containing gabbi tests.

This suite has two features: the contained tests are ordered and there are suite-level fixtures that operate as context managers.

class gabbi.suite.GabbiSuite(tests=())

Bases: unittest.suite.TestSuite

A TestSuite with fixtures.

The suite wraps the tests with a set of nested context managers that operate as fixtures.

If a fixture raises unittest.case.SkipTest during setup, all the tests in this suite will be skipped.

run(result, debug=False)

Override TestSuite run to start suite-level fixtures.

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

Table Of Contents

Previous topic

Fixtures

This Page