--- id: flexmock version: "0.13.0" license: BSD-2-Clause license_treatment: permissive maintenance: active --- # flexmock — flexmock is a testing library for Python that makes it easy to create mocks, stubs and fakes. License: permissive · Maintenance: active · Downloads: 149.0K/mo ## What it is and what it does flexmock is a testing library that lets you create mock, stub, spy, and fake objects for unit testing without pulling in external dependencies. It reads like English sentences rather than API calls—for example, you can write `flexmock(Train).should_receive("get_destination").and_return("Paris").once()` to assert that a method is called exactly once with a specific return value. The library works with unittest, pytest, and doctest out of the box, and its entire public API is type-annotated for editor support and static analysis. You use flexmock when you need to isolate code under test by replacing real objects with controlled doubles. Mocks let you verify that methods were called with expected arguments; spies let you wrap the real method and check how many times it ran; stubs replace parts of objects or classes; and fakes generate placeholder objects. Since it has no external dependencies and only uses the Python standard library, it's lightweight and straightforward to add to any test suite. Use it for: - Verify that a method was called with specific arguments and return value in a unit test. - Spy on real method calls to count invocations or check they never happen with certain inputs. - Replace a database or API client with a stub to test business logic in isolation. - Generate fake objects to populate test fixtures without writing boilerplate classes. - Assert that exception-raising methods are called the correct number of times. - Test code that depends on external services by mocking their interfaces. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. flexmock creates mock, stub, spy, and fake objects for testing Python code, with zero external dependencies and full type annotations. Yes. flexmock is actively maintained, has no external dependencies, supports current Python versions (3.10+), carries a permissive license, and integrates seamlessly with all major test runners. It's a solid choice if you prefer readable, English-like mock declarations over the standard library's unittest.mock API. ## Install pip install flexmock uv add flexmock poetry add flexmock ## Installing flexmock Before you install: Low friction install with no runtime dependencies. Actively maintained as of 2026-01-10, last commit 2026-08-09, and marked Production/Stable. License in practice: BSD-2-Clause permissive license allows broad use, modification, and distribution with minimal restrictions. Quickstart: pip install flexmock from flexmock import flexmock flexmock(SomeClass).should_receive("method_name").and_return("value").once() Requires Python 3.10 or later (supports 3.10, 3.11, 3.12, 3.13, 3.14, and PyPy3). Verify before relying: - Whether the English-like declaration syntax is genuinely easier to learn than unittest.mock for developers new to mocking. - Real-world performance characteristics when mocking complex object hierarchies or large test suites. ## Package facts - License: BSD-2-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 149.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags python mocking library, mock objects testing, spy and stub framework, pytest mock alternative, unittest mock replacement, fake object generator, test double creation, testing, mocking, type-annotated [View on SkillFed](https://skillfed.io/packages/flexmock) · [View on PyPI](https://pypi.org/project/flexmock/)