esp32-testing-library
Test unmodified ESP32 firmware through its wires, in pytest.
esp32tl runs your ESP-IDF image, as built, in the esp32sim
emulator. The test sets up the world around the board, powers it on, and checks what the firmware
does on its pins, UARTs, SD card and network. In the emulator, time is the board's own clock, not
the wall's, so a run is fast and the same every time: all the tests of the GPS alarm clock below
run in a few seconds. On a real ESP32 on a serial port, the same board and console tests run
in wall time.
A shortened test from that example; configure_alarm, TARGET and the buzzer fixture are
defined in its test file, not by esp32tl:
def test_moving_into_the_radius_turns_it_on(board, buzzer):
configure_alarm(board) # the destination, in NVS
board.gnss.fix(at=TARGET.moved(EAST, m(150))) # a GNSS receiver 150 m away
board.power_on()
board.wait(seconds(3))
buzzer.assert_off()
board.gnss.move(heading=WEST, speed=km_h(36)) # drive towards the target
board.wait(seconds(5)) # the 50 m to the radius
board.wait_until(buzzer.is_on, within=seconds(2))
Use in your own project
esp32tl is available on PyPI. The project is alpha software.
With Python 3.11 or newer, install esp32tl from PyPI in your project directory, then explicitly prepare its simulator runtime:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install esp32tl
esp32tl runtime prepare
pytest tests/
Build your firmware beforehand with ESP-IDF or PlatformIO: neither installation nor pytest builds it. Writing tests shows how to point tests at that build. No esp32tl checkout or Rust is needed for this path.
Prebuilt runtimes support Linux x86_64 with glibc (Ubuntu 22.04 or newer) and macOS arm64
(macOS 15 or newer). Windows, musl Linux and other architectures have no prebuilt runtime.
SD card image operations additionally need mtools: brew install mtools on macOS or
sudo apt-get install mtools on Debian/Ubuntu.
As an alternative to PyPI, download the .whl asset from a published
GitHub release, install it with
python -m pip install followed by the downloaded wheel's filename, then run
esp32tl runtime prepare. Preparation downloads the runtime from v<installed package version>;
that GitHub release must be published even when installing a wheel locally. Draft assets are not
available anonymously. To build from source, use the developer path below.
Runtime installation covers version matching, offline reuse and CI.
Independent simulator tests also support parallel runs with pytest-xdist.
Your first green test
This developer path builds the firmware and runs the tests of the GPS alarm clock, a small ESP-IDF application that sounds a buzzer inside a radius of a destination.
You need Python 3.11 or newer, Rust through rustup, Docker running, and network access to GitHub (what each is for).
git clone https://github.com/mateuszsikora/esp32-testing-library.git
cd esp32-testing-library
make setup # .venv, the runner around esp32sim, the ESP32 ROM
firmware/build.sh --examples gps_alarm_clock # the firmware, in the pinned ESP-IDF container
.venv/bin/pytest examples/gps_alarm_clock/tests # its tests, in the emulator
The last command ends with:
examples/gps_alarm_clock/tests/test_alarm.py ......... [100%]
============================== 9 passed in 3.08s ===============================
Once Docker has the ESP-IDF image, the three commands take a few minutes; on a new machine the
first build also pulls the image, 7 GB once unpacked, which can take longer than the rest
(measured).
With a local ESP-IDF's export.sh sourced,
IDF_LOCAL=1 firmware/build.sh --examples gps_alarm_clock builds without Docker
(a local ESP-IDF).
Make it fail
Open examples/gps_alarm_clock/tests/test_alarm.py
and bring the receiver of the first test inside the alarm's 100 m radius:
board.gnss.fix(at=TARGET.moved(EAST, m(50))) # was m(1000)
Run .venv/bin/pytest examples/gps_alarm_clock/tests again. The test fails with what went wrong,
on the board's clock; assert_never_buzzed, a helper of the example's test file, raises it:
E AssertionError: alarm.buzzer expected off after initialization (GPIO 18, level 0); first violation at 1.06781 s: level 1
Below it, the section Captured esp32sim link teardown ends with the run on the board's clock:
every step of the test and the last 200 entries of the console, the GNSS UART and the buzzer, in
the order they happened. An excerpt, with the boot log left out:
the run on the board's clock, 69 entries:
0.000000000 s test board.nvs(partition='nvs')
0.000000000 s test uart.gnss.fix(at=Position(lat=52.22967699772281, lon=21.012967141827147), hdop=0.9, satellites=8)
0.000000000 s test board.power_on(), the world's time 2026-01-01T12:00:00Z
0.000000000 s test board.wait(5 s)
…
0.050060000 s alarm.buzzer out 0
0.053891600 s console gps_alarm_clock: ready
1.000000000 s uart.gnss in $GPRMC,120001.00,A,5213.78062,N,02100.77803,E,0.00,,010126,,,A*40\r\n$GPGGA,120001.00,5213.78062,N,021... (139 bytes)
1.067806337 s alarm.buzzer out 1
…
Undo the change with git restore examples/gps_alarm_clock/tests/test_alarm.py.
What the test did
Read the firmware and its tests side by side. In each test:
pytest.mark.app_path("..")names the ESP-IDF project; the test runs itsbuild/directory.board_profile("gps-alarm-clock")says which UART the GNSS receiver is on and which pin is the buzzer.configure_alarm(board, ...), a helper of the test file, turns aPositionand a radius into the firmware's NVS schema and writes it withboard.nvs(...)before power-on, where the firmware reads it.gnss.fix(...),gnss.move(...)andgnss.lose_fix()drive a model of a GNSS receiver, which writes NMEA sentences into the firmware's UART.board.wait(...)andboard.wait_until(...)let the firmware run on the board's clock; the emulated board runs only while the test waits.buzzeris a fixture of the test file,lines.output("alarm.buzzer"): the GPIO line the firmware drives, read from outside.assert_never_buzzed, another helper there, checks every level the line took, not only the last one.
Nothing in the firmware changes for the test, and the test reads nothing inside it.
Where to go next
- Test your own firmware: writing tests for your firmware goes from where the tests go to running them in CI.
- More examples, each with readable tests (how to build and run them): an SD card data logger, a position tracker sending MQTT over TLS through a cellular modem, a periodic deep-sleep wake and an OBD-II reader over Bluetooth Classic.
- The fixtures, markers and options: the pytest plugin.
- Everything else:
docs/README.mdsays what lives where.
What it can do today
- Run an unmodified ESP-IDF image for the classic ESP32 in esp32sim, or the same
boardandconsoletests on a real ESP32 on a serial port (the serial backend). - Run a PlatformIO build,
.pio/build/<env>/, aspio runleft it, in esp32sim or flashed on the real board (builds). - Feed a UART from a model, a recording, or a real device on a host serial port, such as a GNSS receiver on a USB adapter.
- Drive and read GPIO lines, read the console, and write the NVS partition before power-on.
- Put an SD card holding a FAT image on the SPI pins.
- Model a cellular modem the firmware talks AT to, and a network behind it or behind a Wi-Fi access point, with DNS, NTP, an MQTT broker and an HTTP server in the test.
- Wake the firmware from deep sleep on a timer, and run a day of wakes in seconds.
- Put a Bluetooth Classic peer with the Serial Port Profile beside the board, which the firmware finds, pairs with and talks to.
The esp32tl command runs an image outside pytest (the CLI).
Working on esp32tl
make test sets everything up and runs the whole suite, the repository's own tests and every
example; the first run builds all the firmware in Docker, which takes much longer than one example,
and the SD card tests need mtools
(the development guide,
the test suite).
Contributions follow CONTRIBUTING.md;
a change that alters behaviour updates its documentation in the same pull request.
Metadata
Release files for esp32tl 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| esp32tl-0.4.0.tar.gz | 2.0 MB | With provenance | Details for esp32tl-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| esp32tl-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for esp32tl-0.4.0-py3-none-any.whl |
Total release size: 2.4 MB
Release files / esp32tl-0.4.0.tar.gz
| Download URL | esp32tl-0.4.0.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a026d9cb529fd325598d55e7fec28a0798c65436915c761d330a8c673a4b564
|
|
BLAKE2b-256 checksum How to use checksums |
22b62c15b11bf3c995c37022af147058c03e73b6cf64e8a2a7d76131d1640f49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / esp32tl-0.4.0-py3-none-any.whl
| Download URL | esp32tl-0.4.0-py3-none-any.whl |
|---|---|
| Size | 356.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cde9296bca44ec3b38ab65ea8b9d3a23da8922281086ab0359a2fae2846e6e65
|
|
BLAKE2b-256 checksum How to use checksums |
a9184e5a855d4caf634da893071b6d9dab2f2bbb2ed8f5f8bc7066b953f7fc5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for esp32tl 0.4.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for esp32tl-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA 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.