Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Automatically mocks resources from serverless.yml in pytest using moto.

License

NotificationsYou must be signed in to change notification settings

whisller/pytest-serverless

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.

masterPyPIPythonpytestLicence
MasterPyPI6.2

Pre installation requirements

  • serverless installed
  • pytest installed

Installation

pip install pytest-serverless

Usage

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

Supported resources

AWS::DynamoDB::Table

AWS::SQS::Queue

AWS::SNS::Topic

AWS::S3::Bucket

AWS::KMS::Key

About

Automatically mocks resources from serverless.yml in pytest using moto.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp