Use mock MongoDB server for unit test

Joel James picture Joel James · Apr 10, 2013 · Viewed 12.4k times · Source

I have to implement nosetests for Python code using a MongoDB store. Is there any python library which permits me initializing a mock in-memory MongoDB server?

I am using continuous integration. So, I want my tests to be independent of any MongoDB running server. Is there a way to mock mongoDM Server in memory to test the code independently of connecting to a Mongo server?

Thanks in advance!

Answer

Ross picture Ross · Apr 15, 2013

You could try: https://github.com/vmalloc/mongomock, which aims to be a small library for mocking pymongo collection objects for testing purposes.

However, I'm not sure that the cost of just running mongodb would be prohibitive compared to ensuring some mocking library is feature complete.