--- id: mockito version: "2.0.4" license: MIT license_treatment: permissive maintenance: active --- # mockito — Spying framework License: permissive · Maintenance: active · Downloads: 1.6M/mo ## 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 above — 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 pip install mockito uv add mockito 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_current - Install friction: low - Maintenance: active - Downloads: 1.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags mock library python, stubbing framework, spy on function calls, verify mock interactions, unit test mocking, mock objects testing, stub side effects, testing, mocking, unit-tests [View on SkillFed](https://skillfed.io/packages/mockito) · [View on PyPI](https://pypi.org/project/mockito/)