seaworthy.pytest.fixtures

A number of pytest fixtures or factories for fixtures.

clean_container_fixtures(container, name, scope='class', dependencies=())[source]

Creates a fixture for a container that can be “cleaned”. When a code block is marked with @pytest.mark.clean_<fixture name> then the clean method will be called on the container object before it is passed as an argument to the test function.

Note

This function returns two fixture functions. It is important to keep references to the returned functions within the scope of the tests that use the fixtures.

f1, f2 = clean_container_fixtures(PostgreSQLContainer(), 'postgresql')

class TestPostgresqlContainer
    @pytest.mark.clean_postgresql
    def test_clean_container(self, web_container, postgresql):
        """
        Test something about the container that requires it to have a
        clean state (e.g. database table creation).
        """

    def test_dirty_container(self, web_container, postgresql):
        """
        Test something about the container that doesn't require it to
        have a clean state (e.g. testing something about a dependent
        container).
        """
Parameters:
  • container – A “container” object that is a subclass of ContainerDefinition.
  • name – The fixture name.
  • scope – The scope of the fixture.
  • dependencies – A sequence of names of other pytest fixtures that this fixture depends on. These fixtures will be requested from pytest and so will be setup, but nothing is done with the actual fixture values.
Returns:

A tuple of two fixture functions.

docker_helper()

Default fixture for DockerHelper. Has module scope.

docker_helper_fixture(name='docker_helper', scope='module', **kwargs)[source]

Create a fixture for DockerHelper.

This can be used to create a fixture with a different name to the default. It can also be used to override the scope of the default fixture:

docker_helper = docker_helper_fixture(scope='class')
Parameters:
  • name – The name of the fixture.
  • scope – The scope of the fixture.
  • kwargs – Keyword arguments to pass to the DockerHelper constructor.
image_fetch_fixture(image, name, scope='module')[source]

Create a fixture to fetch an image.

resource_fixture(definition, name, scope='function', dependencies=())[source]

Create a fixture for a resource.

Note

This function returns a fixture function. It is important to keep a reference to the returned function within the scope of the tests that use the fixture.

fixture = resource_fixture(PostgreSQLContainer(), 'postgresql')

def test_container(postgresql):
    """Test something about the PostgreSQL container..."""
Parameters:
  • definition – A resource definition, one of those defined in the seaworthy.definitions module.
  • name – The fixture name.
  • scope – The scope of the fixture.
  • dependencies – A sequence of names of other pytest fixtures that this fixture depends on. These fixtures will be requested from pytest and so will be setup, but nothing is done with the actual fixture values.
Returns:

The fixture function.