pytest-embedded
raw JSON → 2.7.0 verified Mon Apr 27 auth: no python
A pytest plugin designed for embedded system testing. Current version 2.7.0 provides fixtures and utilities for testing firmware on microcontrollers and SoCs, with support for serial, jtag, and qemu backends. Release cadence is irregular, with recent updates focused on compatibility with pytest 8+.
pip install pytest-embedded Common errors
error ModuleNotFoundError: No module named 'pytest_embedded' ↓
cause Package not installed or installed in wrong environment.
fix
Run
pip install pytest-embedded in the correct virtual environment. error AttributeError: 'Dut' object has no attribute 'expect' ↓
cause Using v1.x API where DUT has different method names.
fix
Upgrade to v2.x:
pip install 'pytest-embedded>=2' and use dut.expect(). error TypeError: pytest_embedded_config() missing 1 required positional argument: 'app' ↓
cause Config function not returning a dictionary as expected.
fix
Ensure
pytest_embedded_config returns a dict with required keys (app, port, target). Warnings
breaking In v2.x, the config function must be named `pytest_embedded_config`, not `pytest_embedded_conf` as in v1.x. ↓
fix Rename to `pytest_embedded_config`.
deprecated The `--embedded-boards` CLI option is deprecated in favor of `--target`. ↓
fix Use `--target` instead.
gotcha If you use `pexpect` directly on the DUT, it may conflict with the internal serial handling; use `dut.write()` and `dut.expect()` methods. ↓
fix Use the DUT fixture's read/write methods instead of raw pexpect.
Install
pip install 'pytest-embedded[serial]' pip install 'pytest-embedded[qemu]' pip install 'pytest-embedded[all]' Imports
- pytest_embedded wrong
from embedded import pytest_embeddedcorrectimport pytest_embedded
Quickstart
import pytest
import os
# conftest.py
def pytest_embedded_config():
return {
'app': os.environ.get('APP_PATH', '.'),
'port': os.environ.get('TARGET_PORT', '/dev/ttyUSB0'),
'target': os.environ.get('TARGET', 'esp32'),
}
# test_example.py
def test_basic(dut):
dut.expect('Hello from firmware')
dut.write('test_cmd')
dut.expect('ok', timeout=5)