mongomock-motor is a Python library that provides a best-effort mock for the AsyncIOMotorClient, built on top of the `mongomock` library. It enables developers to test asynchronous MongoDB applications that use `motor` without requiring a running MongoDB instance. The library is currently active, with frequent patch and minor feature releases.
pip install mongomock-motorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `AsyncMongoMockClient` and perform basic asynchronous MongoDB operations (insert, find, update) against it, mimicking the API of `motor.motor_asyncio.AsyncIOMotorClient`.
Thoroughly test critical code paths with both the mock and a real MongoDB instance (e.g., via Docker) to ensure identical behavior. Consult `mongomock` documentation for known limitations.
Plan for migration of your application code to the `PyMongo Async driver` and explore potential mocking solutions for that driver once `motor` is fully deprecated.
Explicitly test BSON type handling in your application when using `mongomock-motor`. If issues arise, consider manual type conversion or reporting the inconsistency to the library maintainers.
Pin exact versions of `mongomock-motor`, `mongomock`, `motor`, and `pymongo` in your `requirements.txt` or `pyproject.toml`. Regularly review changelogs for all related libraries before upgrading.
Ensure `mongomock-motor` is only used within test suites and development environments, never deployed to production.