Use mock MongoDB server for unit test

后端 未结 4 518
萌比男神i
萌比男神i 2020-12-09 17:22

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

4条回答
  •  萌比男神i
    2020-12-09 17:38

    I am also using pymongo and MockupDB is working very well for my purpose (integration tests).

    To use it is as simple as:

    from mockupdb import *
    server = MockupDB()
    port = server.run()
    from pymongo import MongoClient
    client = MongoClient(server.uri)
    import module_i_want_to_patch
    module_i_want_to_patch.client = client
    

    You can check the official tutorial for MockupDB here

提交回复
热议问题