Usage¶
-
pytest_localstack.
patch_fixture
(scope='function', services=None, autouse=False, docker_client=None, region_name=None, kinesis_error_probability=0.0, dynamodb_error_probability=0.0, container_log_level=10, localstack_version='latest', auto_remove=True, pull_image=True, container_name=None, **kwargs)[source]¶ Create a pytest fixture that temporarially redirects all botocore sessions and clients to a Localstack container.
This is not a fixture! It is a factory to create them.
The fixtures that are created by this function will run a Localstack container and patch botocore to direct traffic there for the duration of the tests.
Since boto3 uses botocore to send requests, boto3 will also be redirected.
- Parameters
scope (str, optional) – The pytest scope which this fixture will use. Defaults to
"function"
.services (list, dict, optional) –
One of
A
list
of AWS service names to start in the Localstack container.A
dict
of service names to the port they should run on.
Defaults to all services. Setting this can reduce container startup time and therefore test time.
autouse (bool, optional) – If
True
, automatically use this fixture in applicable tests. Default:False
docker_client (
DockerClient
, optional) – Docker client to run the Localstack container with. Defaults todocker.client.from_env()
.region_name (str, optional) – Region name to assume. Each Localstack container acts like a single AWS region. Defaults to
"us-east-1"
.kinesis_error_probability (float, optional) – Decimal value between 0.0 (default) and 1.0 to randomly inject ProvisionedThroughputExceededException errors into Kinesis API responses.
dynamodb_error_probability (float, optional) – Decimal value between 0.0 (default) and 1.0 to randomly inject ProvisionedThroughputExceededException errors into DynamoDB API responses.
container_log_level (int, optional) – The logging level to use for Localstack container logs. Defaults to
logging.DEBUG
.localstack_version (str, optional) – The version of the Localstack image to use. Defaults to
"latest"
.auto_remove (bool, optional) – If
True
, delete the Localstack container when it stops. Default:True
pull_image (bool, optional) – If
True
, pull the Localstack image before running it. Default:True
container_name (str, optional) – The name for the Localstack container. Defaults to a randomly generated id.
**kwargs – Additional kwargs will be passed to the
LocalstackSession
.
- Returns
A
pytest fixture
.
-
pytest_localstack.
session_fixture
(scope='function', services=None, autouse=False, docker_client=None, region_name=None, kinesis_error_probability=0.0, dynamodb_error_probability=0.0, container_log_level=10, localstack_version='latest', auto_remove=True, pull_image=True, container_name=None, **kwargs)[source]¶ Create a pytest fixture that provides a LocalstackSession.
This is not a fixture! It is a factory to create them.
The fixtures that are created by this function will yield a
LocalstackSession
instance. This is useful for simulating multiple AWS accounts. It does not automatically redirect botocore/boto3 traffic to Localstack (althoughLocalstackSession
has a method to do that.) TheLocalstackSession
instance has factories to create botocore/boto3 clients that will connect to Localstack.- Parameters
scope (str, optional) – The pytest scope which this fixture will use. Defaults to
"function"
.services (list, dict, optional) –
One of:
A
list
of AWS service names to start in the Localstack container.A
dict
of service names to the port they should run on.
Defaults to all services. Setting this can reduce container startup time and therefore test time.
autouse (bool, optional) – If
True
, automatically use this fixture in applicable tests. Default:False
docker_client (
DockerClient
, optional) – Docker client to run the Localstack container with. Defaults todocker.client.from_env()
.region_name (str, optional) – Region name to assume. Each Localstack container acts like a single AWS region. Defaults to
"us-east-1"
.kinesis_error_probability (float, optional) – Decimal value between 0.0 (default) and 1.0 to randomly inject ProvisionedThroughputExceededException errors into Kinesis API responses.
dynamodb_error_probability (float, optional) – Decimal value between 0.0 (default) and 1.0 to randomly inject ProvisionedThroughputExceededException errors into DynamoDB API responses.
container_log_level (int, optional) – The logging level to use for Localstack container logs. Defaults to
logging.DEBUG
.localstack_version (str, optional) – The version of the Localstack image to use. Defaults to
"latest"
.auto_remove (bool, optional) – If
True
, delete the Localstack container when it stops. Default:True
pull_image (bool, optional) – If
True
, pull the Localstack image before running it. Default:True
.container_name (str, optional) – The name for the Localstack container. Defaults to a randomly generated id.
**kwargs – Additional kwargs will be passed to the
LocalstackSession
.
- Returns
A
pytest fixture
.