{"id":24057,"library":"mocket","title":"Mocket","description":"Mocket is a socket mock framework for Python that allows you to mock socket connections and HTTP calls for testing purposes. It supports gevent, asyncio, and SSL, and provides a high-level API similar to httpretty. Current version is 3.14.1, with regular releases.","status":"active","version":"3.14.1","language":"python","source_language":"en","source_url":"https://github.com/mindflayer/python-mocket","tags":["testing","mock","socket","http","asyncio","gevent"],"install":[{"cmd":"pip install mocket","lang":"bash","label":"pip install mocket"}],"dependencies":[],"imports":[{"note":"Main mocket class for mocking socket calls.","symbol":"Mocket","correct":"from mocket import Mocket"},{"note":"Base class for defining mock responses.","symbol":"MocketEntry","correct":"from mocket import MocketEntry"},{"note":"Decorator/context manager to enable mocket sessions.","symbol":"mocketize","correct":"from mocket import mocketize"},{"note":"Do not use the standalone httpretty package; use mocket's plugin instead.","wrong":"import httpretty","symbol":"http.mock","correct":"from mocket.plugins.httpretty import httpretty"}],"quickstart":{"code":"from mocket import mocketize, MocketEntry, Mocket\n\n@mocketize\ndef test_http_get():\n    url = \"http://example.com/\"\n    Mocket.register(MocketEntry(url, body=\"mock response\"))\n    import urllib.request\n    response = urllib.request.urlopen(url)\n    assert response.read() == b\"mock response\"\n","lang":"python","description":"Basic usage mocking an HTTP GET request."},"warnings":[{"fix":"Use @mocketize decorator or 'with mocketize()' context manager to automatically enable/disable mocks.","message":"Mocket replaces global socket functions; ensure tests are isolated and mocketize is scoped properly to avoid leakage.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'from mocket.plugins.httpretty import httpretty' instead of 'import httpretty'.","message":"Mocket's httpretty plugin is not compatible with the standalone httpretty library; import from mocket.plugins.httpretty not httpretty directly.","severity":"gotcha","affected_versions":"all"},{"fix":"Review changelog for 3.13.9 and 3.13.11 for strict mode and custom can_handle logic.","message":"The 'strict' mode and custom request-matching via callables are new in 3.13.x; old patterns may not work.","severity":"deprecated","affected_versions":">=3.13.0"},{"fix":"Upgrade to latest mocket and ensure pytest-asyncio >=0.23.","message":"Fixture 'event_loop' removed in pytest-asyncio; Mocket 3.13.8 addresses this but tests relying on old event_loop may break.","severity":"breaking","affected_versions":">=3.13.8"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from mocket.plugins.httpretty import httpretty'.","cause":"People try 'from mocket import httpretty' instead of using the plugin module.","error":"ImportError: cannot import name 'httpretty' from 'mocket'"},{"fix":"Ensure mocket version >= 3.0 and import as 'from mocket import MocketEntry'.","cause":"Old versions or import path changed; MocketEntry is directly in mocket module.","error":"AttributeError: module 'mocket' has no attribute 'MocketEntry'"},{"fix":"Wrap test function with @mocketize or use 'with mocketize():' block.","cause":"Attempting to use Mocket.register outside of a mocketized session.","error":"RuntimeError: Mocket not initialized. Use @mocketize decorator."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}