A PYTHON TESTING LIBRARY

Your search code.
Your test suite.
No cluster required.

Keep the OpenSearch client API. Replace the server with a stateful, in-memory fake. Test what happens after a document is written, found, updated, and deleted.

uv add --dev openmock

Python 3.11+ · Sync + async clients · MIT licensed

test_books.pyPYTHON
import opensearchpy
from openmock import openmock

@openmock
def test_find_a_book():
    client = opensearchpy.OpenSearch()
    client.index(
        index="books", id="1",
        body={"title": "Dune"},
    )
    result = client.search(
        index="books",
        body={"query": {
            "match": {"title": "Dune"}
        }},
    )
    assert result["hits"]["total"]["value"] == 1
✓ test_find_a_book PASSED

One decorator. Real state transitions. An ordinary assertion.

01 / THE WORKFLOW

Write the test around
what your application does.

  1. 01

    Decorate the test

    @openmock patches client constructors for the decorated call. Construct your client inside that scope.

  2. 02

    Exercise a workflow

    Index documents, run supported queries, and update or delete records. Later calls see the state left by earlier calls.

  3. 03

    Assert the result

    Check your application’s outcome using familiar OpenSearch-shaped responses. Each decorated call starts with fresh client caches.

02 / A DELIBERATELY SMALL FAKE

Fast feedback for
everyday document flows.

Use the mock where a small, predictable model is enough. Keep real-server tests for the behavior that needs OpenSearch.

Explore the supported API →

Documents & queries

CRUD, bulk, search, count, pagination, and scrolling. Selected term, match, range, bool, and aggregation behavior.

Sync & async tests

Fake clients for both programming styles. Core document workflows are shared; sub-client coverage differs.

A clear boundary

No relevance engine, full analyzer pipeline, distributed execution, or complete Painless runtime. Verify those with a real cluster.

03 / EXPLORE THE FAKE

A workbench for your test data.

Optional tools for manual experiments. Each runs with its own in-memory state.

BROWSER

Management console

Explore indices, search, fake security, and ingest pipelines with Streamlit.

openmockInstall the web extra
HTTP

REST bridge

Try the supported HTTP routes from curl or another local tool.

openmock serveInstall the rest extra
DESKTOP

Tkinter inspector

Inspect fake data in a desktop interface using Python’s Tk support.

openmock guiRequires Tk and a graphical display
Set up the exploration tools →

BUILD CONFIDENCE, ONE TEST AT A TIME

Start with a small test.

Install the library, decorate a function, and make your first assertion.