skillfed

mongomock-motor

Library for mocking AsyncIOMotorClient built on top of mongomock.

mongomock-motor v0.0.36 1.5M downloads/30d#3,873 on PyPI123
Permissive license MIT AGING released

What it is and what it does

mongomock-motor wraps the mongomock library to provide an async-compatible mock of MongoDB's AsyncIOMotorClient. It lets you write and test async MongoDB code without spinning up a real database server, using the same async/await patterns you'd use with the actual motor library. The mock implements the core AsyncIOMotorClient, Database, and Collection interfaces, returning coroutines that can be awaited in your test code.

The package is built on top of mongomock, which handles the in-memory database simulation, and motor, which defines the async API contract. It's intended for unit and integration testing of applications that use motor for async MongoDB access. Since it's a pure-Python implementation with no external database dependency, it's fast and lightweight for test environments.

Use it for:

  • Unit test async MongoDB code without requiring a test MongoDB instance or Docker container.
  • Mock motor client in CI/CD pipelines where spinning up a database would slow down test runs.
  • Develop and test async MongoDB queries locally without database setup overhead.
  • Verify async query logic and collection operations in isolation before integration testing.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides an async mock client for MongoDB that mimics the AsyncIOMotorClient API, allowing you to test async MongoDB code without a running database.

Yes, if you write async MongoDB code with motor and want to test without a real database. The low install friction, permissive license, and current Python version support make it a straightforward addition to a test suite. The aging maintenance status (455 days since last release) is a minor concern for a stable mock library, but the lack of security vulnerabilities and active repository suggest it remains usable. Verify that the mock covers the specific motor APIs your code relies on before committing to it.

Install

mongomock-motor on PyPI

pip

pip install mongomock-motor

uv

uv add mongomock-motor

poetry

poetry add mongomock-motor

Installing mongomock-motor

Before you install

Low install friction with a pure-Python wheel. Maintenance status is aging—last release was 455 days ago—but the repository is not archived and the package supports current Python versions through 3.13.

License in practice

MIT license is permissive; you can use this package freely in commercial and open-source projects with minimal restrictions.

Quickstart

pip install mongomock-motor

from mongomock_motor import AsyncMongoMockClient

async def test():
    collection = AsyncMongoMockClient()['db']['collection']
    await collection.insert_one({'a': 1})
    docs = await collection.find({}).to_list(None)
    return docs

Requires Python 3.8 or later; async/await syntax required in calling code.

Verify before relying

  • Completeness of AsyncIOMotorClient API coverage—which methods and features are fully mocked vs. stubbed or missing.
  • Performance characteristics and suitability for large test datasets or high-volume mock operations.
  • Known limitations or edge cases where mock behavior diverges from actual Motor/MongoDB behavior.

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0,>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 2 — mongomock, motor
Maintenance aging — 455 days since the last release
Last repo commit
First released
Downloads 1,467,915/month — #3,873 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: mongomock_motor-0.0.36-py3-none-any.whl

Keywords: library, mongodb

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

async mongodb mockmotor client testingmongodb async mockasyncio motor mockmongodb test doublemock asyncio motor clientmongodb unit testing
testingmongodbasync-mock

More Testing packages