Skip to main content

pytest-serverless

Mock local resources for serverless framework.

master PyPI Python pytest Licence
Build Status PyPI 3.10.1, 4.6.6, 5.2.4

Installation

pip install pytest-serverless

Your project has to have pytest installed.

What problem it tries to solve?

When building your project with serverless most likely you will create resources like dynamodb tables, sqs queues, sns topics.

During writing tests you will have to mock those in moto.

This pytest plugin tries to automate this process by reading serverless.yml file and create moto mocks of resources for you.

Usage

Assuming your serverless.yml file looks like:

service: my-microservice
resources:
 Resources:
   TableA:
     Type: 'AWS::DynamoDB::Table'
     DeletionPolicy: Delete
     Properties:
       TableName: ${self:service}.my-table
       AttributeDefinitions:
         - AttributeName: id
           AttributeType: S
         - AttributeName: company_id
           AttributeType: S
       KeySchema:
         - AttributeName: id
           KeyType: HASH
       GlobalSecondaryIndexes:
         - IndexName: company_id
           KeySchema:
             - AttributeName: company_id
               KeyType: HASH
           Projection:
             ProjectionType: ALL
           ProvisionedThroughput:
             ReadCapacityUnits: 10
             WriteCapacityUnits: 30
       ProvisionedThroughput:
         ReadCapacityUnits: 10
         WriteCapacityUnits: 30

To start using my-microservice.my-table table in your tests just mark your test with @pytest.mark.usefixtures("serverless"), and rest will be done by plugin.

import boto3
import pytest


@pytest.mark.usefixtures("serverless")
def test():
    table = boto3.resource("dynamodb").Table("my-microservice.my-table")
    count_of_items = len(table.scan()["Items"])
    assert count_of_items == 0

Supported resources

AWS::DynamoDB::Table

AWS::SQS::Queue

Issues?

Plugin is in early stage of development, so you might find some bugs or missing functionality.

If possible create pull request (with tests) that fixes particular problem.

Metadata

Release files for pytest-serverless 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-serverless 0.8.0
File Size Uploaded
pytest-serverless-0.8.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-serverless 0.8.0
File Interpreter ABI Platform
pytest_serverless-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / pytest-serverless-0.8.0.tar.gz

Download URL pytest-serverless-0.8.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
38795b9f8c40532e08cf160b014a6187b4ea4b8ee8bf00e60701f6dccc91493c
BLAKE2b-256 checksum
How to use checksums
0da3adb75dbaad817a6b723c9c6df62da7b14fbb02b5228d4e49eb203f712ed8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0a2 CPython/3.6.5 Darwin/19.0.0

Release files / pytest_serverless-0.8.0-py3-none-any.whl

Download URL pytest_serverless-0.8.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25cae32608a9d3000c594ca02748598f12c2001cd4605552dade2a8e416fed71
BLAKE2b-256 checksum
How to use checksums
30d89139dd94910b352ac688e6ecd1082ffd64720f8d9524f3d5caa75b1cd5d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0a2 CPython/3.6.5 Darwin/19.0.0

Release history Release notifications | RSS feed

1.0.0

2 release files

0.16.0

2 release files

0.14.0

2 release files

0.13.3

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

This release

0.8.0 This release

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page