Skip to content
/ spawndb Public

A simple helper for SQLAlchemy to create test databases on the fly.

Notifications You must be signed in to change notification settings

ppmdo/spawndb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpawnDB

This is a simple library that helps in the creation of test databases for Python projects that use SQLAlchemy.

It's aim it's to seamlessly handle creation of a separate test database, including the creation of all schemas, their objects and finally, handling the destruction of the test database when it's no longer needed.

Usage

To create a test database, use the init_test_db function.

This function expects two arguments:

  • database_url: sqlalchemy.engine.URL
  • metadata: sqlalchemy.schema.MetaData

It will return an instantiated Engine for the test database which you can use for your database logics.

# Sample usage for Pytest
from spawndb import init_test_db, destroy_test_db

def my_cool_test():
    db_engine = init_test_db(database_url, sqla_metadata)
    
    try:
        # your stuff goes here
    
    finally:
        destroy_test_db(database_url)

About

A simple helper for SQLAlchemy to create test databases on the fly.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published