Mock MicroPython libraries for CPython development and testing.
mockro lets developers write firmware code that uses real MicroPython APIs —
import machine, import network, and so on — and run it on a normal computer
without hardware attached. It is useful for local development, unit tests, CI,
and prototyping before deploying to a device.
Originally derived from educational workflows, mockro is packaged as a
standalone development and testing tool for embedded and IoT projects.
Install with uv:
uv add --dev mockroOr with pip:
pip install mockroOnce mockro is installed in the environment, plain Python invocations work:
uv run python main.py
# or
python main.pyYou can also use the explicit wrappers:
mockro run main.py
# or
python -m mockro main.pymockro registers a pytest plugin. Just run:
pytestand import machine will work in your tests and the code they import.
Note: by default
mockroonly installs MicroPython-specific module names such asmachine,network, andusocket. It does not shadow CPython stdlib modules likesocket,time,os,json, orasyncio, because those are needed by pytest and other tooling. Useusocket,utime,uos,ujson, anduasyncioin testable code, or run the code throughmockro run/python -m mockroto get the non-ualiases as well.
In conftest.py or test fixtures:
import mockro
mockro.patch("machine.Pin.value", return_value=1)
mockro.patch("network.WLAN.isconnected", return_value=True)Or temporarily:
with mockro.override(machine_Pin_value=1):
...mockro init my_projectThis creates a project with pyproject.toml, conftest.py, starter source,
tests, and .pyi stubs so editors know the mocked MicroPython APIs.
mockro includes mocks for the full MicroPython standard library plus
common port-specific modules:
machine,network,bluetooth,framebuf,gc,micropythonusocket/socket,utime/time,uos/os,usys/sysujson/json,ubinascii/binascii,uhashlib/hashlibuerrno/errno,uheapq/heapq,uasyncio/asynciouctypes/ctypes,ucollections/collections,ustruct/structuselect/select,uzlib/zlibneopixel,dht,onewire,ds18x20esp,esp32,rp2,pyb,samd,zephyr
Full documentation is available at mockro.readthedocs.io.
MIT