pytest-embedded-serial-esp

2.7.0 · active · verified Thu Apr 16

pytest-embedded-serial-esp is a pytest plugin that extends the pytest-embedded framework to work specifically with Espressif target boards via serial communication. As part of the broader pytest-embedded ecosystem, it enables automated testing, flashing, and interaction with ESP32, ESP8266, and other Espressif SoCs. The library is actively maintained by Espressif Systems, with version 2.7.0 being the latest, and undergoes frequent updates, often including new features and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic test using `pytest-embedded-serial-esp` to communicate with an Espressif target. The `@pytest.mark.parametrize('embedded_services', ['serial', 'esp'], indirect=True)` decorator is crucial to activate the necessary services for serial communication and Espressif-specific features, including auto-flashing by esptool. The `dut: Dut` fixture provides the interface to interact with the device under test, primarily using `expect_exact()` to wait for specific serial output. Ensure an Espressif device with appropriate firmware (e.g., a 'Hello World' example) is connected via serial.

import pytest
from pytest_embedded import Dut

@pytest.mark.parametrize('embedded_services', ['serial', 'esp'], indirect=True)
def test_basic_expect(dut: Dut):
    # Example: wait for a specific output from the ESP device
    # The 'serial' service provides basic serial communication.
    # The 'esp' service enables esptool-specific functionalities like auto-flashing.
    dut.expect_exact('Hello world!', timeout=10)
    print(f"Device output: {dut.before.decode()}")
    # Additional interaction, e.g., sending commands or expecting more output
    # dut.write('command\n')
    # dut.expect('response')

view raw JSON →