Run an in-memory DynamoDBLocal for testing
Project description
Run-DynamoDBLocal
AWS makes DynamoDBLocal -- a service that mirrors the API of DynamoDB and runs locally -- available to their customers for testing purposes. This Python packages facilitates running that service as a subprocess of the testing harness.
Install
$ pip install 'run-dynamodblocal[boto3]'
Leave off the [boto3]
if you don't intend to use this package's ability to patch boto3
.
Usage
Quickstart
With thanks to ncoghlan:
import boto3_mocking
from contextlib import ExitStack
import os.path
import run_dynamodblocal
import unittest
# If patching isn't engaged when the run_dynamodblocal context is entered, an
# exception will be thrown
boto3_mocking.engage_patching()
class MyTest(unittest.TestCase):
def setUp(self):
with ExitStack() as resources:
dynamodblocal_path = os.path.expanduser(
# wherever you keep the unpacked service binaries
'~/Downloads/dynamodb_local_latest'
)
resources.enter_context(
run_dynamodblocal.rddbl.patched_into_boto3(dynamodblocal_path)
)
# Enter any other contexts for this test class...
addCleanup(resources.pop_all().close)
# Define test methods here
Diving Deeper
This package provides two different context managers which run the DynamoDBLocal service -- one of which integrates with boto3
to automatically redirect the dynamodb
service to this DynamoDBLocal instance. The DynamoDBLocal started will use the -inMemory
flag, so it does not persist on disk after the test run is over and doesn't waste testing time committing information to disk.
Context Manager | Description |
---|---|
run_dynamodblocal.in_subprocess |
The most fundamental; runs the server and returns the port number as the context value |
run_dynamodblocal.patched_into_boto3 |
Runs the server and patches it into the boto3 library |
It also provides the run_dynamodblocal.LocalDbOps
class, which supports refreshing the database schema and populated data based on a Serverless configuration and some basic JSON-type data.
Contributing
- Fork it on GitHub (https://github.com/rtweeks/run-dynamodblocal)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request (on GitHub)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for run_dynamodblocal-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9913ed8965b1712f87430ec62476a23bc58db0ce9993878fd30ebf22745408d |
|
MD5 | 225b19d0a5c3c5132383aaf7924d711e |
|
BLAKE2b-256 | 646d9327fa96e4497ac1c97f98ac490efc44e53cb517fba8849cad0d622eaae7 |