{"id":23135,"library":"openmock","title":"openmock - OpenSearch Mock for Python Testing","description":"A Python library for mocking OpenSearch (Elasticsearch) operations in unit tests. Provides a lightweight in-memory mock that simulates OpenSearch behaviors without needing a real cluster. Current version: 3.2.0, requires Python >=3.10. Release cadence irregular.","status":"active","version":"3.2.0","language":"python","source_language":"en","source_url":"https://github.com/vvanhaecke/openmock","tags":["opensearch","testing","mock","opensearchpy","python"],"install":[{"cmd":"pip install openmock","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"Old import path or custom class name confusion; the correct decorator/context manager is OpenMock.","wrong":"from openmock import MockOpenSearch","symbol":"OpenMock","correct":"from openmock import OpenMock"}],"quickstart":{"code":"from openmock import OpenMock\nfrom opensearchpy import OpenSearch\n\nwith OpenMock():\n    client = OpenSearch()\n    # index a document\n    client.index(index='my-index', body={'title': 'Test'})\n    # search\n    result = client.search(index='my-index', body={'query': {'match_all': {}}})\n    print(result['hits']['hits'][0]['_source']['title'])  # Output: Test","lang":"python","description":"Basic usage: use OpenMock as a context manager to mock OpenSearch client calls."},"warnings":[{"fix":"Upgrade Python to >=3.10 and use 'from openmock import OpenMock'.","message":"Version 3.x dropped support for Python <3.10 and changed the import from 'openmock' (previously 'openmock.OpenMock' was sometimes imported incorrectly). Ensure your tests run on Python >=3.10.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Place all related OpenSearch operations within a single with block, or use the decorator form '@OpenMock()' for a whole test function.","message":"OpenMock does not persist state between different with-blocks or across separate test cases. Each context manager starts with a fresh mock cluster.","severity":"gotcha","affected_versions":"all"},{"fix":"Check the openmock documentation for the list of supported APIs. For unsupported operations, consider mocking manually or using a real test cluster.","message":"The mock only supports a subset of OpenSearch APIs. Advanced features like snapshot/restore, scroll, or compatibility with specific OpenSearch plugins may not be available.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Upgrade to latest version: pip install openmock --upgrade. Then use: from openmock import OpenMock","cause":"Using an older version of openmock (<3.0) where the import path was different, or a typo.","error":"AttributeError: module 'openmock' has no attribute 'OpenMock'"},{"fix":"Wrap your code with OpenMock() context manager or decorator.","cause":"OpenMock not activated. The OpenSearch client is trying to connect to a real cluster instead of the mock.","error":"opensearchpy.exceptions.ConnectionError: ConnectionError(('Connection refused', ...)) caused by: ConnectionError(('Connection refused', ...))"},{"fix":"Ensure you are using the correct API and that the call happens within the OpenMock context. Verify the method and parameters match exactly.","cause":"Using openmock with opensearchpy's mock assertions incorrectly, or the mock is not set up for that specific call.","error":"AssertionError: Expected mocked call not found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}