Skip to main content

Pytest plugin for AWS integration tests

Project description

PyPI Travis-CI Codecov https://img.shields.io/github/license/mintel/pytest-localstack.svg https://img.shields.io/github/issues/mintel/pytest-localstack.svg https://img.shields.io/github/forks/mintel/pytest-localstack.svg https://img.shields.io/github/stars/mintel/pytest-localstack.svg

pytest-localstack is a plugin for pytest to create AWS integration tests via a Localstack Docker container.

Read The Docs

Requires:

  • pytest >= 3.3.0

  • Docker

Tested against Python >= 3.6.

Features

  • Create pytest fixtures that start and stop a Localstack container.

  • Temporarily patch botocore to redirect botocore/boto3 API calls to Localstack container.

  • Plugin system to easily extend supports to other AWS client libraries such as aiobotocore.

Example

import boto3
import pytest_localstack

localstack = pytest_localstack.patch_fixture(
    services=["s3"],  # Limit to the AWS services you need.
    scope='module',  # Use the same Localstack container for all tests in this module.
    autouse=True,  # Automatically use this fixture in tests.
)

def test_s3_bucket_creation():
    s3 = boto3.resource('s3')  # Botocore/boto3 will be patched to use Localstack
    assert len(list(s3.buckets.all())) == 0
    bucket = s3.Bucket('foobar')
    bucket.create()
    assert len(list(s3.buckets.all())) == 1

Services

  • apigateway

  • cloudformation

  • cloudwatch

  • dynamodb

  • dynamodbstreams

  • ec2

  • es

  • firehose

  • iam

  • kinesis

  • lambda

  • logs

  • redshift

  • route53

  • s3

  • secretsmanager

  • ses

  • sns

  • sqs

  • ssm

  • stepfunctions

  • sts

Installation

$ pip install pytest-localstack

TODO

  • More detailed docs.

  • Break Docker container running out of LocalstackSession.

  • Make botocore patching more comprehensible.

  • Add common test resource fixture factories i.e. S3 buckets, SQS queues, SNS topics, etc.

  • Test this works for non-localhost Docker containers.

  • Add other client libraries such as aiobotocore.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_localstack-0.6.1.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

pytest_localstack-0.6.1-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_localstack-0.6.1.tar.gz.

File metadata

  • Download URL: pytest_localstack-0.6.1.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-150-generic

File hashes

Hashes for pytest_localstack-0.6.1.tar.gz
Algorithm Hash digest
SHA256 fd0928a837ef226882bf51e17c8c69368ccb7e57bdd66a92901e807919f49308
MD5 17649a1c74d8ec0c502ae2a84927a0a4
BLAKE2b-256 078fbac39c3847d027da9683f482145b3ac7595b1eb9b7666d4368cd4d809566

See more details on using hashes here.

File details

Details for the file pytest_localstack-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_localstack-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-150-generic

File hashes

Hashes for pytest_localstack-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e0f8f2f7d86030f71914e316b2c46cc2f9c924b7e95c0ff34902b58358ddaab
MD5 b4178745da932390a42b4a3b58b10a50
BLAKE2b-256 57cec47153bec21d1a210f4337901b97c79b25b2e9654dbcec49b0ac40c3e8d5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page