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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_embedded_wokwi-2.0.0a1.tar.gz.
File metadata
- Download URL: pytest_embedded_wokwi-2.0.0a1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
892c1fefa45cfb9d4a9b52934ed68e41cd2a239186f606fd745e88cf4f1a8c8b
|
|
| MD5 |
e157c6cdfd5295bc718793673ca5596e
|
|
| BLAKE2b-256 |
43cbdeb57f7523136c304e5d891affa359ec8ba52ceff33db43d7dd58aa02d3c
|
File details
Details for the file pytest_embedded_wokwi-2.0.0a1-py3-none-any.whl.
File metadata
- Download URL: pytest_embedded_wokwi-2.0.0a1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b78a23b39ee9a60abafee43cbc6bae858805e8497512485a003aa0be3a9061b4
|
|
| MD5 |
bdca070213830385cb2665d4b666ad06
|
|
| BLAKE2b-256 |
e9b50ec142b17fe0fd7ede347a93126c7cfb9647ca2235052f8f3672dfc3890c
|