Skip to main content

mockro

Mock MicroPython libraries for CPython development and testing.

mockro lets students write code that looks exactly like real MicroPython — import machine, import network, and so on — while running and testing it on a normal computer without any hardware attached.

Quick start

Install with uv:

uv add --dev mockro

Or with pip:

pip install mockro

Run a script with mocks

Once mockro is installed in the environment, plain Python invocations work:

uv run python main.py
# or
python main.py

You can also use the explicit wrappers:

mockro run main.py
# or
python -m mockro main.py

Run tests with mocks

mockro registers a pytest plugin. Just run:

pytest

and import machine will work in your tests and the code they import.

Note: by default mockro only installs MicroPython-specific module names such as machine, network, and usocket. It does not shadow CPython stdlib modules like socket, time, os, json, or asyncio, because those are needed by pytest and other tooling. Use usocket, utime, uos, ujson, and uasyncio in testable code, or run the code through mockro run / python -m mockro to get the non-u aliases as well.

Override behavior for assignments

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):
    ...

Create a new assignment

mockro init my_assignment

This scaffolds a project with pyproject.toml, conftest.py, starter source, tests, and .pyi stubs so editors know the mocked MicroPython APIs.

Mocked modules

mockro includes mocks for the full MicroPython standard library plus common port-specific modules:

  • machine, network, bluetooth, framebuf, gc, micropython
  • usocket / socket, utime / time, uos / os, usys / sys
  • ujson / json, ubinascii / binascii, uhashlib / hashlib
  • uerrno / errno, uheapq / heapq, uasyncio / asyncio
  • uctypes / ctypes, ucollections / collections, ustruct / struct
  • uselect / select, uzlib / zlib
  • neopixel, dht, onewire, ds18x20
  • esp, esp32, rp2, pyb, samd, zephyr

License

MIT

Metadata

Release files for mockro 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mockro 0.1.0
File Size Uploaded Provenance Actions
mockro-0.1.0.tar.gz 35.1 kB Without provenance Details for mockro-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mockro 0.1.0
File Interpreter ABI Platform Actions
mockro-0.1.0-py3-none-any.whl Python 3 none any Details for mockro-0.1.0-py3-none-any.whl

Total release size: 93.9 kB

Release files / mockro-0.1.0.tar.gz

Download URL mockro-0.1.0.tar.gz
Size 35.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f37864954e30b55a6029ca6ee75a2374adc1e7289e87970880281766157677fb
BLAKE2b-256 checksum
How to use checksums
8e6bef648000484cd2484ba3fa69506bbb3f9b657de1c3c3915b2249a2ba3847
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / mockro-0.1.0-py3-none-any.whl

Download URL mockro-0.1.0-py3-none-any.whl
Size 58.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcbd08ea0ecfbea1a6587b16da661b7d0b12ee3fda14b73322f4d0595bd3a31f
BLAKE2b-256 checksum
How to use checksums
1ddabf66811ee4827ef9bf0e9173641eb0842e4b1b08dda80077dd24376ebb27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Security for mockro 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page