{"id":17272878,"url":"https://github.com/konradhalas/mimid","last_synced_at":"2026-03-16T17:31:43.693Z","repository":{"id":57441674,"uuid":"191054001","full_name":"konradhalas/mimid","owner":"konradhalas","description":"Modern mocking library for Python.","archived":false,"fork":false,"pushed_at":"2022-12-21T11:18:48.000Z","size":60,"stargazers_count":11,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-27T21:52:07.975Z","etag":null,"topics":["mocking","software-development","tdd","testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/konradhalas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-09T20:49:57.000Z","updated_at":"2023-09-02T09:53:00.000Z","dependencies_parsed_at":"2023-01-30T03:30:28.901Z","dependency_job_id":null,"html_url":"https://github.com/konradhalas/mimid","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konradhalas%2Fmimid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konradhalas%2Fmimid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konradhalas%2Fmimid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konradhalas%2Fmimid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/konradhalas","download_url":"https://codeload.github.com/konradhalas/mimid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844036,"owners_count":21170505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mocking","software-development","tdd","testing"],"created_at":"2024-10-15T08:49:41.717Z","updated_at":"2026-03-16T17:31:43.664Z","avatar_url":"https://github.com/konradhalas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mimid\n\n[![Build Status](https://travis-ci.org/konradhalas/mimid.svg?branch=master)](https://travis-ci.org/konradhalas/mimid)\n[![Coverage Status](https://coveralls.io/repos/github/konradhalas/mimid/badge.svg?branch=master)](https://coveralls.io/github/konradhalas/mimid?branch=master)\n[![License](https://img.shields.io/pypi/l/mimid.svg)](https://pypi.python.org/pypi/mimid/)\n[![Version](https://img.shields.io/pypi/v/mimid.svg)](https://pypi.python.org/pypi/mimid/)\n[![Python versions](https://img.shields.io/pypi/pyversions/mimid.svg)](https://pypi.python.org/pypi/mimid/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n\nModern mocking library for Python.\n\n**⚠️ This project is under heavy development, API could be unstable.**\n\n## Installation\n\nTo install `mimid`, simply use `pip`:\n\n```\n$ pip install mimid\n```\n\n## Quick start\n\n\n```python\nfrom mimid import mock, every, verify, any, gt\n\ndef add(a: int, b: int) -\u003e int:\n    return a + b\n\ndef test_add():\n    add_mock = mock(add)\n    every(add_mock).returns(5)    \n    \n    result = add_mock(2, 2)\n    \n    assert result == 5\n    verify(add_mock).with_args(any(), gt(0)).called(times=1)\n```\n\n## Features\n\nMimid supports following features:\n\n- easy mock behaviour configuration and verification\n- works with classes and plain functions\n- fully type hinted - it works with IDE's and type checkers\n- clean API - not too much magic\n\n## Why not `mock`?\n\nPython built-in `mock` module is an awesome tool. It's a first choice if you want to mock something in your tests.\n\nHowever it has a few disadvantages:\n\n- it doesn't work well with modern IDEs (e.g. auto completion) and type checkers\n- it's difficult to define different behaviours for different cases\n- it allows too much freedom, you can do anything with your mock object, even if you didn't define any behaviour\n\n## Inspiration\n\nMimid is highly inspired by mocking frameworks from a JVM world, like [mockito] or [mockk].\n\n## Usage\n\nThere are 3 simple steps in the `mimid` mocking workflow:\n\n1. [Creation](#creation)\n2. [Configuration](#configuration)\n3. [Verification](#verification)\n\nAdditionally you can use [matchers](#matchers) in both configuration and verification steps. \n\n### Creation\n\nYou have to use `mock` function to create your mock object. It works both with classes and functions.\n\nClass example:\n\n```python\nfrom mimid import mock\n\nclass A:\n\n    def foo(self, param):\n        pass\n        \nclass_mock = mock(A) \n```\n\nFunction example:\n\n```python\nfrom mimid import mock\n\ndef foo(param):\n    pass\n\nfunction_mock = mock(foo)\n```\n\n### Configuration\n\nBefore you call your mock (function or method) you have to configure its behaviour. Use `every` with additional\nmethods (`returns`, `raises`, ...) to define how it should works during your test.\n\n```python\nfrom mimid import mock, every\n\ndef foo(param):\n    pass\n\nfunction_mock = mock(foo)\nevery(function_mock).returns(1)\n``` \n\nYou can also specify arguments which should trigger defined behaviour.\n\n```python\nfrom mimid import mock, every\n\ndef foo(param):\n    pass\n\nfunction_mock = mock(foo)\nevery(function_mock).with_args(param=2).returns(1)\nevery(function_mock).with_args(param=3).raises(Exception())\n```\n\nIf you want to define property behaviour you have to use `prop` function:\n\n```python\nfrom mimid import mock, every, prop\n\nclass A:\n    \n    @property\n    def x(self) -\u003e int:\n        pass\n        \nclass_mock = mock(A) \nevery(prop(class_mock).x).returns(1)\n```\n\nAvailable configurations:\n\n| Configuration    | Description                           |\n| ---------------- | ------------------------------------- |\n| `returns`        | return given value                    |\n| `returns_many`   | return each value from provided list  |\n| `raises`         | raise given exception                 | \n| `execute`        | call given callable                   | \n\n### Verification\n\nAt the end of your test you can check if mock was called as expected with `verify`.\n\n```python\nfrom mimid import mock, verify\n\ndef foo(param):\n    pass\n\nfunction_mock = mock(foo)\n\n... # mock calls\n\nverify(function_mock).called(times=2)\n```\n\nYou can use the same `with_args` also during verification step:\n\n```python\nfrom mimid import mock, verify\n\ndef foo(param):\n    pass\n\nfunction_mock = mock(foo)\n\n... # mock calls\n\nverify(function_mock).with_args(param=1).called(times=2)\n```\n\n### Matchers\n\nYou can use matchers during configuration (`with_args`) and verification (`with_args`, `called`) steps. You can also combine matchers with `|` or `\u0026` and negate it with `~`.\n\nExample:\n\n```python\nfrom mimid import mock, every, verify, gt, lt, gte\n\ndef foo(param):\n    pass\n\nfunction_mock = mock(foo)\nevery(function_mock).with_args(gt(0)).returns(1)\n\nresult = function_mock(10)\n\nassert result == 1\nverify(function_mock).with_args(gt(5) | lt(15)).called(times=gte(1))\n\n```\n\n`capture` is a special matcher - it behaves like `any()` but additionally it \nstores given argument in provided slot.\n\nExample:\n\n```python\nfrom mimid import mock, every, slot, capture\n\ndef foo(param):\n    pass\n\nfunction_mock = mock(foo)\nparam_slot = slot()\nevery(function_mock).with_args(capture(param_slot)).execute(lambda: param_slot.value + 1)\n\nresult = function_mock(1)\n\nassert result == 2\nassert param_slot.value == 1\n\n```\n\nAvailable matchers:\n\n| Matcher          | Description                           |\n| ---------------- | ------------------------------------- |\n| `any`            | match any value                       |\n| `eq`             | match equal value                     |\n| `lt`             | match lower value                     | \n| `lte`            | match lower or equal value            | \n| `gt`             | match greater value                   | \n| `gte`            | match greater or equal value          | \n| `capture`        | capture provided argument             | \n\n## Authors\n\nCreated by [Konrad Hałas][halas-homepage].\n\n[halas-homepage]: https://konradhalas.pl\n[mockito]: https://site.mockito.org\n[mockk]: https://github.com/mockk/mockk\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonradhalas%2Fmimid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkonradhalas%2Fmimid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonradhalas%2Fmimid/lists"}