skillfed

mockito

Spying framework

mockito v2.0.4 1.6M downloads/30d#3,750 on PyPI
Permissive license MIT Active released

What it is and what it does

Mockito is a mocking and spying framework for Python unit tests, originally inspired by the Java library of the same name. It lets you stub out method calls to return specific values, verify that functions were called with expected arguments, and replace real dependencies with controlled fakes during testing. The core workflow is straightforward: use `when()` to set up a stub that returns a value when called, use the stubbed code in your test, then call `unstub()` to clean up.

Version 2 adds first-class support for async/await, properties, descriptors, and ordered verification across multiple mocks. The framework handles context managers automatically, checking that stubs were actually used unless disabled. It has no runtime dependencies beyond Python itself, making it lightweight to add to any test suite.

Use it for:

  • Stub external API calls (e.g., requests library) to return fake responses without hitting the network
  • Verify that your code calls a dependency with the correct arguments and number of times
  • Mock filesystem operations (os.path.exists, open) to test error handling without touching disk
  • Test async code by mocking async functions and verifying their call patterns
  • Replace database queries with controlled mock responses to isolate unit tests from data layer

Worth the install?

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

Mockito is a spying and stubbing framework for Python that lets you mock out dependencies, verify interactions, and stub side effects in unit tests.

Yes. Mockito is a mature, actively maintained testing framework with zero dependencies, permissive licensing, and broad Python version support. It solves a core testing need—mocking and verification—with a clean API. No known vulnerabilities and low install friction make it a straightforward addition to any test suite.

Install

mockito on PyPI

pip

pip install mockito

uv

uv add mockito

poetry

poetry add mockito

Installing mockito

Before you install

Low friction: pure Python wheel with no runtime dependencies. Actively maintained with recent release (121 days ago). Supports Python >=3.8 and targets current Python versions.

License in practice

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

Quickstart

pip install mockito

from mockito import when, mock, unstub
import os

when(os.path).exists('/foo').thenReturn(True)
result = os.path.exists('/foo')  # returns True
unstub()

Requires Python >=3.8

Verify before relying

  • Whether async/await support covers all common async testing patterns
  • Performance characteristics when mocking large numbers of interactions
  • Compatibility with popular test runners beyond pytest

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 121 days since the last release
First released
Downloads 1,570,213/month — #3,750 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: mockito-2.0.4-py3-none-any.whl

Tags

mock library pythonstubbing frameworkspy on function callsverify mock interactionsunit test mockingmock objects testingstub side effects
testingmockingunit-tests

More Testing packages