Skip to main content

Pytest plugin for AWS integration tests

Project description

pytest-localstack

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.

Change Log

0.4.0 (2019-08-21)

  • Add EC2 service.

  • Add IAM service.

  • Add Secret Manager service.

  • Add Step Functions service.

  • Add STS service.

0.3.2 (2019-08-16)

  • Track/restore original boto3.DEFAULT_SESSION during patching.

0.3.1 (2019-08-13)

  • Fix exclusion of tests from installed packages.

0.3.0 (2019-07-02)

  • Add CloudWatch Logs service.

0.2.0 (2019-03-06)

  • Use botocore to determine default AWS region (will us-east-1 fallback).

  • Replace use of pytest.config with pytest_configure() hook.

0.1.5 (2018-08-17)

  • Fix a bug involving our patched botocore Session trying to access _internal_components and getting _components instead.

0.1.4 (2018-08-03)

  • Fix pinned install requirements conflict between pytest and pluggy.

0.1.3 (2018-07-17)

  • Fix for botocore >= 1.10.58.

0.1.2 (2018-06-22)

  • Broke out LocalstackSession into RunningSession which doesn’t start localstack itself.

0.1.1 (2018-04-23)

  • Fixed bug where patched botocore clients wouldn’t populated the _exceptions attribute.

0.1.0 (2018-03-13)

  • Initial release

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.4.0.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_localstack-0.4.0-py2.py3-none-any.whl (24.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-localstack-0.4.0.tar.gz.

File metadata

  • Download URL: pytest-localstack-0.4.0.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.1

File hashes

Hashes for pytest-localstack-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2e072f337de9e87d3eb916a965b2604d82b7a84c62a2e17787cf9caabef89f68
MD5 4a6ed831208803a0f291932a3aeeb7a8
BLAKE2b-256 fdf864cbe0bbb07152ff9d5a41adca81e91060cec30f9c24b82d30d934bd485a

See more details on using hashes here.

File details

Details for the file pytest_localstack-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_localstack-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.1

File hashes

Hashes for pytest_localstack-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 83b75fa17cabdbc89449ae41323466451df87dd5a7c807cbe524c8adcd5ad5f6
MD5 345c863d08da13e800c5d6c8b9ba7167
BLAKE2b-256 261b352fda464bd41307e5dbe2d6c2fa48d73d28ad2d72b66df233f3d6b4166b

See more details on using hashes here.

Supported by

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