Registry / testing / mocket

mocket

JSON →
library3.14.1pypypi✓ verified 90d ago

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.

pip install mocket
INSTALL
IMPORT
SIG · MOCKET
M
mocket
testingpythonv3.14.1
Install
1.9s avg
Import
389ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.14.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.404s · 20MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.9s · import 0.374s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Mocket
✓ from mocket import Mocket
Main mocket class for mocking socket calls.
MocketEntry
✓ from mocket import MocketEntry
Base class for defining mock responses.
mocketize
✓ from mocket import mocketize
Decorator/context manager to enable mocket sessions.
http.mock
✓ from mocket.plugins.httpretty import httpretty
✗ import httpretty
Do not use the standalone httpretty package; use mocket's plugin instead.

Basic usage mocking an HTTP GET request.

from mocket import mocketize, MocketEntry, Mocket @mocketize def test_http_get(): url = "http://example.com/" Mocket.register(MocketEntry(url, body="mock response")) import urllib.request response = urllib.request.urlopen(url) assert response.read() == b"mock response"
Debug
Known issues
gotchaMocket replaces global socket functions; ensure tests are isolated and mocketize is scoped properly to avoid leakage.
fix
Use @mocketize decorator or 'with mocketize()' context manager to automatically enable/disable mocks.
affects: all
gotchaMocket's httpretty plugin is not compatible with the standalone httpretty library; import from mocket.plugins.httpretty not httpretty directly.
fix
Use 'from mocket.plugins.httpretty import httpretty' instead of 'import httpretty'.
affects: all
deprecatedThe 'strict' mode and custom request-matching via callables are new in 3.13.x; old patterns may not work.
fix
Review changelog for 3.13.9 and 3.13.11 for strict mode and custom can_handle logic.
affects: >=3.13.0
breakingFixture 'event_loop' removed in pytest-asyncio; Mocket 3.13.8 addresses this but tests relying on old event_loop may break.
fix
Upgrade to latest mocket and ensure pytest-asyncio >=0.23.
affects: >=3.13.8
Errors
Common errors & fixes
ImportError: cannot import name 'httpretty' from 'mocket'
People try 'from mocket import httpretty' instead of using the plugin module.
fix
Use 'from mocket.plugins.httpretty import httpretty'.
AttributeError: module 'mocket' has no attribute 'MocketEntry'
Old versions or import path changed; MocketEntry is directly in mocket module.
fix
Ensure mocket version >= 3.0 and import as 'from mocket import MocketEntry'.
RuntimeError: Mocket not initialized. Use @mocketize decorator.
Attempting to use Mocket.register outside of a mocketized session.
fix
Wrap test function with @mocketize or use 'with mocketize():' block.
Upgrade
Version history
3.14.1latest on PyPI · released Feb 22, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
9
Resources
mocket — pip install mocket · libregistry