Skip to content

Example of using mongomock for testing in a global mongo db class in a flask app

Notifications You must be signed in to change notification settings

alkc/flask-mongomock-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing a pymongo/Flask app using pytest and mongomock

This repo contains an example on how to use mongomock to replace a pymongo.MongoClient inside a Flask app.

The dependencies, test cases, and structure of the app are based on a real project where I was scratching my head over this exact problem.

The setup of the db.MongoDB class imported and initialized in app.py is based on the MongoAdapter in Clinical-Genomics/scout

To try it out, clone this repo, install the dependencies in requirements.txt and run pytest:

git clone https://github.com/alkc/flask-mongomock-example.git
cd flask-mongomock-example
pip install --requirement requirements.txt
pytest .

I'm open for feedback if you think there is a smarter/better way of doing this.

About

Example of using mongomock for testing in a global mongo db class in a flask app

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages