Skip to content

espressif/pytest-embedded

Folders and files

NameName
Last commit message
Last commit date
Mar 18, 2025
Mar 13, 2025
Nov 12, 2024
Mar 13, 2025
Mar 13, 2025
Mar 13, 2025
Mar 13, 2025
Mar 13, 2025
Mar 13, 2025
Mar 13, 2025
Mar 13, 2025
Mar 13, 2025
Jan 14, 2025
Apr 26, 2021
Dec 29, 2022
Jan 27, 2025
Jun 5, 2023
Mar 25, 2025
Jan 21, 2025
Mar 13, 2025
Apr 29, 2024
Nov 14, 2024
Nov 14, 2024
Dec 23, 2021
Feb 6, 2025
Nov 12, 2024
Mar 13, 2025
Jun 9, 2023
Mar 25, 2025

Repository files navigation

pytest-embedded

Documentation Status Python 3.7+

A pytest plugin that has multiple services available for various functionalities. Designed for embedded testing.

Installation

pytest-embedded pytest-embedded-serial pytest-embedded-serial-esp pytest-embedded-idf pytest-embedded-qemu pytest-embedded-arduino pytest-embedded-wokwi pytest-embedded-nuttx

Packages under this repo mainly use semantic versioning. Sometimes a bug fix version may contain some non-breaking new features as well.

It is recommended to use ~=1.0 to get rid of breaking changes, and use the latest new features. For example,

pip install -U pytest-embedded~=1.0

Quickstart

  • pip install -U pytest-embedded~=1.0
  • Create a file test_basic.py
from pytest_embedded import Dut


def test_basic_expect(redirect, dut: Dut):
    with redirect():
        print('this would be redirected')

    dut.expect('this')
    dut.expect_exact('would')
    dut.expect('[be]{2}')
    dut.expect_exact('redirected')
  • Run the test with pytest, the result would be like:
collected 1 item

test_basic.py .                                                        [100%]

============================= 1 passed in 0.01s =============================
  • if run with pytest -s, the output would be as follows:
collected 1 item

test_basic.py 2022-01-01 12:34:56 this would be redirected
.

============================= 1 passed in 0.01s =============================

The print line is also duplicated to console output.

Extra Services

You can activate more services with pytest --embedded-services service[,service] to enable extra fixtures and functionalities. These services are provided by several optional dependencies. You can install them via pip as well.

Available services:

  • serial: serial port utilities.
  • esp: auto-detect target/port by esptool.
  • idf: auto-detect more app info with ESP-IDF specific rules, auto-flash the binary into the target.
  • jtag: openocd/gdb utilities
  • qemu: running test cases on QEMU instead of the real target.
  • arduino: auto-detect more app info with arduino specific rules, auto-flash the binary into the target.
  • wokwi: running test cases with Wokwi instead of the real target.
  • nuttx: service for nuttx project, optionally with espressif devices.

Resources