MongoDB Helpers¶
-
class
test_helpers.mongo.TemporaryDatabase(**kwargs)¶ Creates a temporary MongoDB database that is destroyed automatically.
Parameters: Instances of this class will create a bare MongoDB database with a single collection named
test_helperscontaining a single document with a create date for tracking purposes. When the test process exits all databases created will be destroyed automatically. Under the hood it usespymongoand registers a single cleanup function with :func`atexit.register`.Usage Example
from test_helpers import mongo _testing_db = mongo.TemporaryDatabase() def setup_module(): _testing_db.create()
-
create()¶ Create the temporary database if it does not exist.
-
drop()¶ Drop the temporary database if it was created.
-
set_environment()¶ Export MongoDB environment variables for the database.
This exports the
MONGOHOST,MONGOPORT, andMONGODATABASEenvironment variables
-