botocore¶
Test resource factory for the botocore library.
-
class
pytest_localstack.contrib.botocore.
BotocoreTestResourceFactory
(localstack_session)[source]¶ Create botocore clients to interact with a
LocalstackSession
.Parameters: localstack_session ( LocalstackSession
) – The session that this factory should create test resources for.-
client
(service_name, *args, **kwargs)[source]¶ Create a botocore client that will use Localstack.
Arguments are the same as
botocore.session.Session.create_client()
.
-
default_session
¶ Return a default botocore Localstack Session.
Most applications only need one Session.
-
-
class
pytest_localstack.contrib.botocore.
DefaultCredentialProvider
(session=None)[source]¶ Provide some default credentials for Localstack clients.
-
class
pytest_localstack.contrib.botocore.
LocalstackEndpointResolver
(localstack_session, endpoints)[source]¶ Resolve AWS service endpoints based on a LocalstackSession.
-
construct_endpoint
(service_name, region_name=None)[source]¶ Resolve an endpoint for a service and region combination.
-
get_available_endpoints
(service_name, partition_name='aws', allow_non_regional=False)[source]¶ List the endpoint names of a particular partition.
-
valid_regions
¶ Return a list of regions we can resolve endpoints for.
-
-
class
pytest_localstack.contrib.botocore.
Session
(localstack_session, *args, **kwargs)[source]¶ A botocore Session subclass that talks to Localstack.
-
pytest_localstack.contrib.botocore.
contribute_to_module
(pytest_localstack)[source]¶ Add
patch_fixture()
topytest_localstack
.
-
pytest_localstack.contrib.botocore.
create_credential_resolver
()[source]¶ Create a credentials resolver for Localstack.
-
pytest_localstack.contrib.botocore.
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.
- A
- 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
.- scope (str, optional) – The pytest scope which this fixture will use.
Defaults to