Skip to main content

Make pytest-embedded plugin work with the Wokwi CLI.

Project description

pytest-embedded-wokwi

pytest-embedded service for running tests on Wokwi instead of the real target.

Wokwi supports most ESP32 targets, including: esp32, esp32s2, esp32s3, esp32c3, esp32c6, and esp32h2. In addition, it supports a wide range of peripherals, including sensors, displays, motors, and debugging tools.

Running the tests with Wokwi requires an internet connection. Your firmware is uploaded to the Wokwi server for the duration of the simulation, but it is not saved on the server. On-premises Wokwi installations are available for enterprise customers.

Wokwi API Tokens

Before using this plugin, you need to create a free Wokwi account and generate an API key. You can then set the WOKWI_CLI_TOKEN environment variable to the API key.

Linux / Mac OS / WSL:

export WOKWI_CLI_TOKEN="your-api-key"

Windows PowerShell:

$env:WOKWI_CLI_TOKEN="your-api-key"

Usage

To run your tests with Wokwi, make sure to specify the wokwi service when running pytest, e.g.:

pytest --embedded-services idf,wokwi

Writing Tests

When writing tests for your firmware, you can use the same pytest fixtures and assertions as you would for local testing. The main difference is that your tests will be executed in the Wokwi simulation environment and you have access to the Wokwi API for controlling the simulation through the wokwi fixture.

All interactions with the Wokwi simulation is through the wokwi.client - wokwi-python-client

For example, you can use wokwi.client.set_control() to control virtual components in the simulation, such as buttons, LEDs, and other peripherals. Whole documentations can be found at Wokwi Documentation

Button test:

import logging
from pytest_embedded_wokwi import Wokwi
from pytest_embedded import Dut


def test_gpio(dut: Dut, wokwi: Wokwi):
    LOGGER = logging.getLogger(__name__)

    LOGGER.info("Waiting for Button test begin...")
    dut.expect_exact("Butston test")

    for i in range(3):
        LOGGER.info(f"Setting button pressed for {i + 1} seconds")
        wokwi.client.set_control("btn1", "pressed", 1)

        dut.expect_exact(f"Button pressed {i + 1} times")
        wokwi.client.set_control("btn1", "pressed", 0)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_embedded_wokwi-2.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_embedded_wokwi-2.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_embedded_wokwi-2.1.1.tar.gz.

File metadata

  • Download URL: pytest_embedded_wokwi-2.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for pytest_embedded_wokwi-2.1.1.tar.gz
Algorithm Hash digest
SHA256 90b1534d7af841e29b5eb85fddcf8abf79ca4f6270a17a11b98ed0aa4bf0eca8
MD5 4b5d732e44597493703918f9833117f0
BLAKE2b-256 b1d8bf142ca2e11c5444858a2f69343c55f708a013f3f463d1dfdb0115230f7d

See more details on using hashes here.

File details

Details for the file pytest_embedded_wokwi-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_embedded_wokwi-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9286e0cc4fee886c43a505b4f7768f27d647d54520c033f2e4c3a1826adaf723
MD5 463b88d60b7c42827efb6a1f232253fd
BLAKE2b-256 f0e6f417ed791201234bad3aaaaa3008ba07e2b417fd08e607473aa09f646b6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page