All Projects → whisller → pytest-serverless

whisller / pytest-serverless

Licence: MIT license
Automatically mocks resources from serverless.yml in pytest using moto.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pytest-serverless

pytest-emoji
A pytest plugin that adds emojis to your test result report 😍
Stars: ✭ 41 (+57.69%)
Mutual labels:  pytest
pytest-test-groups
A Pytest plugin that gives you a way to split your tests into groups of a specific size
Stars: ✭ 37 (+42.31%)
Mutual labels:  pytest
favv
Fullstack Web Application Framework With FastAPI + Vite + VueJS. Streamlit for rapid development.
Stars: ✭ 17 (-34.62%)
Mutual labels:  boto3
python-pytest-harvest
Store data created during your `pytest` tests execution, and retrieve it at the end of the session, e.g. for applicative benchmarking purposes.
Stars: ✭ 44 (+69.23%)
Mutual labels:  pytest
pytest-testrail
pytest plugin for integration with TestRail, for creating testruns and updating results
Stars: ✭ 88 (+238.46%)
Mutual labels:  pytest
mimesis-factory
Mimesis integration with factory_boy
Stars: ✭ 42 (+61.54%)
Mutual labels:  pytest
pytest-mongodb
pytest plugin for mocking MongoDB with fixtures
Stars: ✭ 56 (+115.38%)
Mutual labels:  pytest
export-dynamodb
Export Amazon DynamoDb to CSV or JSON
Stars: ✭ 52 (+100%)
Mutual labels:  boto3
nuts
NUTS defines a desired network state and checks it against a real network using pytest and nornir.
Stars: ✭ 47 (+80.77%)
Mutual labels:  pytest
botor
Reticulate wrapper on 'boto3' with convenient helper functions -- aka "boto fo(u)r R"
Stars: ✭ 28 (+7.69%)
Mutual labels:  boto3
pytest-datafixtures
Data fixtures for pytest made simple
Stars: ✭ 24 (-7.69%)
Mutual labels:  pytest
emacs-python-pytest
run pytest inside emacs
Stars: ✭ 105 (+303.85%)
Mutual labels:  pytest
python-package-template
Easy to use template for great PyPi packages
Stars: ✭ 19 (-26.92%)
Mutual labels:  pytest
covdefaults
A coverage plugin to provide sensible default settings
Stars: ✭ 38 (+46.15%)
Mutual labels:  pytest
aws-security-test
No description or website provided.
Stars: ✭ 14 (-46.15%)
Mutual labels:  boto3
pytest-csv
CSV reporter for pytest.
Stars: ✭ 16 (-38.46%)
Mutual labels:  pytest
pytest-html-reporter
Generates a static html report based on pytest framework
Stars: ✭ 69 (+165.38%)
Mutual labels:  pytest
Motorola-Moto-E-condor-unbrick
Tools for Motorola Moto E XT1021, XT1022, XT1025 condor unbrick
Stars: ✭ 31 (+19.23%)
Mutual labels:  moto
pytest-pipeline
Pytest plugin for functional testing of data analysis pipelines
Stars: ✭ 19 (-26.92%)
Mutual labels:  pytest
cognises-flask
Flask Cognises: AWS Cognito group based authorization with user management
Stars: ✭ 16 (-38.46%)
Mutual labels:  boto3

pytest-serverless

Automatically mocks resources defined in serverless.yml file using moto and uses them in pytest.

This way you can focus on writing tests rather than defining enormous list of fixtures.

master PyPI Python pytest Licence
Master PyPI 6.2

Pre installation requirements

  • serverless installed
  • pytest installed

Installation

pip install pytest-serverless

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

Just mark your test with @pytest.mark.usefixtures("serverless") and pytest-serverless will automatically create my-microservice.my-table dynamodb table.

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

You can use a custom serverless file path setting the envionmnet variable SERVERLESS_FILE_PATH.

$ export SERVERLESS_FILE_PATH=/path/to/serverless.yml

You can use choose both sls or serverless command to run, settings the environment variable SERVERLESS_COMMAND. It will only accpets sls or serverless values.

$ export SERVERLESS_COMMAND=sls

Supported resources

AWS::DynamoDB::Table

AWS::SQS::Queue

AWS::SNS::Topic

AWS::S3::Bucket

AWS::KMS::Key

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].