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 |
|---|---|---|---|---|
6.2 |
Pre installation requirements
serverlessinstalledpytestinstalled
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
Metadata
Release files for pytest-serverless 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-serverless-1.0.0.tar.gz | 5.2 kB | Without provenance | Details for pytest-serverless-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_serverless-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_serverless-1.0.0-py3-none-any.whl |
Total release size: 11.6 kB
Release files / pytest-serverless-1.0.0.tar.gz
| Download URL | pytest-serverless-1.0.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa221b90a095a62d8dea0f97c74c43be8ad5dc04637b1a82c16ad8a3ed29f7e6
|
|
BLAKE2b-256 checksum How to use checksums |
3dac2cf86b407bb959898d71a169b99ece24024452816d120e47a3ee328597eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.7.9 Darwin/21.4.0
|
Release files / pytest_serverless-1.0.0-py3-none-any.whl
| Download URL | pytest_serverless-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42be79fadf3696fd1e08a6d34b752f6e7ae86624462ad58e13dfc226a1c70aad
|
|
BLAKE2b-256 checksum How to use checksums |
2c95e9cc29caf478b3e28cc9f87c33a3aaa80bfd8e3933bba574919e553afa4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.7.9 Darwin/21.4.0
|
Security for pytest-serverless 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.