Registry / database / mongomock-motor

mongomock-motor

JSON →
library0.0.36pypypi✓ verified 22d ago

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-motor
INSTALL
IMPORT
SIG · MONGOMOCK-MOTOR
M
mongomock-motor
databasepythonv0.0.36
Install
3.1s avg
Import
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.36 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 30.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 0.000s · 33MB
31MB installed
● package 31MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncMongoMockClient
from mongomock_motor import AsyncMongoMockClient
from mongomock_motor import AsyncMongoMockClient

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`.

import asyncio from mongomock_motor import AsyncMongoMockClient async def main(): client = AsyncMongoMockClient() # Create a mock client db = client['mydatabase'] collection = db['mycollection'] # Insert a document insert_result = await collection.insert_one({"name": "Test Document", "value": 123}) print(f"Inserted document with ID: {insert_result.inserted_id}") # Find a document found_doc = await collection.find_one({"name": "Test Document"}) print(f"Found document: {found_doc}") assert found_doc['value'] == 123 # Update a document update_result = await collection.update_one( {"name": "Test Document"}, {"$set": {"value": 456}} ) print(f"Modified {update_result.modified_count} document(s).") updated_doc = await collection.find_one({"name": "Test Document"}) print(f"Updated document: {updated_doc}") assert updated_doc['value'] == 456 # Close the mock client (good practice, though not strictly necessary for mock) await client.close() if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
gotchamongomock-motor provides a 'best effort mock' and may not perfectly replicate all corner cases, complex query behaviors, or newer features of a real MongoDB instance or the `motor` driver. Discrepancies may arise in highly specific scenarios.
fix
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.
affects: All versions
deprecatedThe underlying `motor` library is scheduled for deprecation on May 14, 2026, with critical bug fixes ending May 14, 2027. Users are recommended to migrate to the `PyMongo Async driver`. This will affect the long-term relevance and maintenance of `mongomock-motor` as `motor` itself is phased out.
fix
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.
affects: All versions
gotchaSpecific BSON type handling, such as `uuidRepresentation` settings, might not behave identically in `mongomock-motor` compared to a real `motor` connection. This can lead to unexpected errors or data mismatches when dealing with UUIDs or other complex BSON types.
fix
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.
affects: <=0.0.36
breakingCompatibility with `mongomock`, `motor`, and `pymongo` versions is crucial. Upgrades in any of these underlying libraries (e.g., `mongomock` dropping Python 2 support or `motor` requiring `PyMongo 4.0+`) can introduce breaking changes that might not be immediately reflected or supported by `mongomock-motor`.
fix
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.
affects: All versions
gotchaThis library is intended for unit and integration testing purposes only. It should never be used as a substitute for a real MongoDB connection in production environments.
fix
Ensure `mongomock-motor` is only used within test suites and development environments, never deployed to production.
affects: All versions
Upgrade
Version history
0.0.36latest on PyPI · released May 16, 2025
Audit
Dependencies
mongomockrequiredCore library providing MongoDB mocking functionality.
motoroptionalThe library that mongomock-motor mocks. While not a direct runtime dependency for `mongomock-motor` itself, it is implicitly required by the user's application code that is being tested.
Agent activity
16 hits · last 30 days
node
14
Resources
mongomock-motor — pip install mongomock-motor · libregistry