- Notifications
You must be signed in to change notification settings - Fork12
Automatically mocks resources from serverless.yml in pytest using moto.
License
whisller/pytest-serverless
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Automatically mocks resources defined in serverless.yml file usingmoto and uses them inpytest.
This way you can focus on writing tests rather than defining enormous list of fixtures.
master | PyPI | Python | pytest | Licence |
---|---|---|---|---|
6.2 |
serverless
installedpytest
installed
pip install pytest-serverless
Assuming yourserverless.yml
file looks like:
service:my-microserviceresources:Resources:TableA:Type:'AWS::DynamoDB::Table'DeletionPolicy:DeleteProperties:TableName:${self:service}.my-tableAttributeDefinitions: -AttributeName:idAttributeType:S -AttributeName:company_idAttributeType:SKeySchema: -AttributeName:idKeyType:HASHGlobalSecondaryIndexes: -IndexName:company_idKeySchema: -AttributeName:company_idKeyType:HASHProjection:ProjectionType:ALLProvisionedThroughput:ReadCapacityUnits:10WriteCapacityUnits:30ProvisionedThroughput:ReadCapacityUnits:10WriteCapacityUnits:30
Just mark your test with@pytest.mark.usefixtures("serverless")
andpytest-serverless
will automatically createmy-microservice.my-table
dynamodb table.
importboto3importpytest@pytest.mark.usefixtures("serverless")deftest():table=boto3.resource("dynamodb").Table("my-microservice.my-table")count_of_items=len(table.scan()["Items"])assertcount_of_items==0
You can use a custom serverless file path setting the envionmnet variableSERVERLESS_FILE_PATH
.
$export SERVERLESS_FILE_PATH=/path/to/serverless.yml
You can use choose bothsls
orserverless
command to run, settings the environment variableSERVERLESS_COMMAND
. It will only accpetssls
orserverless
values.
$export SERVERLESS_COMMAND=sls
About
Automatically mocks resources from serverless.yml in pytest using moto.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.