API Reference

class testservices.service.T

The type of an object that represents a service

alias of TypeVar(‘T’)

class testservices.service.Service

This is the basic thing that testservices manages. It often ends up representing a TCP port and some credential to connect to it, but, conceptually, can be anything from a piece of hardware to a simple file on disk.

name: str | None = None

The name of this service

possible() bool

Returns True if it’s possible to create this service or check if it already exists.

exists() bool

Returns True if the service represented by this object has already been created.

create() None

Do any work needed to create this service so it can be used.

get() T

Return an object that makes most sense to use this service. This method may be called many times during the life of the service.

destroy() None

Do any work needed to destroy this service and release its resources.

class testservices.provider.T

The type of object returned by services in this Provider.

alias of TypeVar(‘T’)

exception testservices.provider.NoAvailableService
class testservices.provider.Provider(*services: Service[T])

This provides a single service from a selection of alternatives. The intention is to provide the first service that is possible in the current context, create it if doesn’t already exist and then return the object representing it.

Databases

class testservices.services.databases.Database(host: str, port: int | None, username: str, password: str | None, database: str | None, dialect: str | None = None, driver: str | None = None)

The credentials to connect to a database.

class testservices.services.databases.DatabaseContainer(image: str, version: str, port: int, dialect: str, start_wait: float = 0.05, ready_phrases: Sequence[bytes] = (), ready_poll_wait: float = 0.01, ready_timeout: float = 5, driver: str | None = None, volumes: Dict[str, Dict[str, str]] | None = None, always_pull: bool = False, env: Dict[str, str] | None = None, name: str | None = None)
get() Database

Return an object that makes most sense to use this service. This method may be called many times during the life of the service.

class testservices.services.databases.PostgresContainer(image: str = 'docker.io/library/postgres', version: str = 'latest', driver: str = 'psycopg', always_pull: bool = False)
class testservices.services.databases.MariadbContainer(image: str = 'docker.io/library/mariadb', version: str = 'latest', driver: str | None = None, always_pull: bool = False)
class testservices.services.databases.ClickhouseContainer(image: str = 'docker.io/clickhouse/clickhouse-server', version: str = 'latest', driver: str | None = None, database: str | None = None, always_pull: bool = False)
class testservices.services.databases.DatabaseFromEnvironment(url: str = 'DB_URL', *, check: bool = True, timeout: float = 5, poll_frequency: float = 0.05)

A Database service where the credentials are extracted from an environment variable.

possible() bool

Returns True if it’s possible to create this service or check if it already exists.

get() Database

Return an object that makes most sense to use this service. This method may be called many times during the life of the service.