Skip to content

Commit 7409898

Browse files
committed
refactor: remove deprecated Wokwi CLI options and related code
1 parent 4cbc9ce commit 7409898

File tree

4 files changed

+29
-78
lines changed

4 files changed

+29
-78
lines changed

pytest-embedded-wokwi/README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ Wokwi supports most ESP32 targets, including: esp32, esp32s2, esp32s3, esp32c3,
66

77
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.
88

9-
#### Wokwi CLI installation
10-
11-
The Wokwi plugin uses the [Wokwi CLI](https://github.com/wokwi/wokwi-cli) to interact with the wokwi simulation server. You can download the precompiled CLI binaries from the [releases page](https://github.com/wokwi/wokwi-cli/releases). Alternatively, on Linux or Mac OS, you can install the CLI using the following command:
12-
13-
```bash
14-
curl -L https://wokwi.com/ci/install.sh | sh
15-
```
16-
17-
And on Windows:
18-
19-
```powershell
20-
iwr https://wokwi.com/ci/install.ps1 -useb | iex
21-
```
22-
239
#### Wokwi API Tokens
2410

2511
Before using this plugin, you need to create a free Wokwi account and [generate an API key](https://wokwi.com/dashboard/ci). You can then set the `WOKWI_CLI_TOKEN` environment variable to the API key.
@@ -44,8 +30,32 @@ To run your tests with Wokwi, make sure to specify the `wokwi` service when runn
4430
pytest --embedded-services idf,wokwi
4531
```
4632

47-
To limit the amount of simulation time, use the `--wokwi-timeout` flag. For example, to set the simulation time limit to 60 seconds (60000 milliseconds):
33+
#### Writing Tests
4834

49-
```
50-
pytest --embedded-services idf,wokwi --wokwi-timeout=60000
35+
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.
36+
37+
All interactions with the Wokwi simulation is through the `wokwi.client` - [wokwi-python-client](https://github.com/wokwi/wokwi-python-client)
38+
39+
For example, you can use `wokwi.client.set_control()` to control virtual components in the simulation, such as buttons, LEDs, and other peripherals.
40+
Whole documentations can be found at [Wokwi Documentation](https://wokwi.github.io/wokwi-python-client/)
41+
42+
Button test:
43+
```py
44+
import logging
45+
from pytest_embedded_wokwi import Wokwi
46+
from pytest_embedded import Dut
47+
48+
49+
def test_gpio(dut: Dut, wokwi: Wokwi):
50+
LOGGER = logging.getLogger(__name__)
51+
52+
LOGGER.info("Waiting for Button test begin...")
53+
dut.expect_exact("Butston test")
54+
55+
for i in range(3):
56+
LOGGER.info(f"Setting button pressed for {i + 1} seconds")
57+
wokwi.client.set_control("btn1", "pressed", 1)
58+
59+
dut.expect_exact(f"Button pressed {i + 1} times")
60+
wokwi.client.set_control("btn1", "pressed", 0)
5161
```

pytest-embedded-wokwi/pytest_embedded_wokwi/wokwi.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ def __init__(
4343
firmware_resolver: IDFFirmwareResolver,
4444
wokwi_diagram: t.Optional[str] = None,
4545
app: t.Optional['IdfApp'] = None,
46-
_wokwi_cli_path: t.Optional[str] = None, # ignored for compatibility
47-
_wokwi_timeout: t.Optional[int] = None, # ignored for compatibility
48-
_wokwi_scenario: t.Optional[str] = None, # ignored for compatibility
4946
meta: t.Optional[Meta] = None,
5047
**kwargs,
5148
):
@@ -74,12 +71,8 @@ def __init__(
7471
self.create_diagram_json()
7572
wokwi_diagram = os.path.join(self.app.app_path, 'diagram.json')
7673

77-
# Filter out Wokwi-specific kwargs that shouldn't be passed to subprocess.Popen
78-
wokwi_specific_kwargs = {'wokwi_timeout', 'wokwi_scenario', 'wokwi_diagram', 'firmware_resolver', 'app'}
79-
filtered_kwargs = {k: v for k, v in kwargs.items() if k not in wokwi_specific_kwargs}
80-
8174
# Initialize parent class
82-
super().__init__(msg_queue=msg_queue, meta=meta, **filtered_kwargs)
75+
super().__init__(msg_queue=msg_queue, meta=meta, **kwargs)
8376

8477
# Connect and start simulation
8578
try:
@@ -155,6 +148,7 @@ def close(self):
155148
def __del__(self):
156149
"""Destructor to ensure cleanup when object is garbage collected."""
157150
self.close()
151+
super().__del__()
158152

159153
def terminate(self):
160154
"""Terminate the Wokwi connection."""

pytest-embedded/pytest_embedded/dut_factory.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ def _fixture_classes_and_options_fn(
145145
qemu_prog_path,
146146
qemu_cli_args,
147147
qemu_extra_args,
148-
wokwi_cli_path,
149-
wokwi_timeout,
150-
wokwi_scenario,
151148
wokwi_diagram,
152149
skip_regenerate_image,
153150
encrypt,
@@ -313,9 +310,6 @@ def _fixture_classes_and_options_fn(
313310

314311
classes[fixture] = Wokwi
315312
kwargs[fixture].update({
316-
'wokwi_cli_path': wokwi_cli_path,
317-
'wokwi_timeout': wokwi_timeout,
318-
'wokwi_scenario': wokwi_scenario,
319313
'wokwi_diagram': wokwi_diagram,
320314
'msg_queue': msg_queue,
321315
'app': None,
@@ -659,9 +653,6 @@ def create(
659653
qemu_prog_path: t.Optional[str] = None,
660654
qemu_cli_args: t.Optional[str] = None,
661655
qemu_extra_args: t.Optional[str] = None,
662-
wokwi_cli_path: t.Optional[str] = None,
663-
wokwi_timeout: t.Optional[int] = 0,
664-
wokwi_scenario: t.Optional[str] = None,
665656
wokwi_diagram: t.Optional[str] = None,
666657
skip_regenerate_image: t.Optional[bool] = None,
667658
encrypt: t.Optional[bool] = None,
@@ -708,9 +699,6 @@ def create(
708699
qemu_prog_path: QEMU program path.
709700
qemu_cli_args: QEMU CLI arguments.
710701
qemu_extra_args: Additional QEMU arguments.
711-
wokwi_cli_path: Wokwi CLI path.
712-
wokwi_timeout: Wokwi timeout.
713-
wokwi_scenario: Wokwi scenario path.
714702
wokwi_diagram: Wokwi diagram path.
715703
skip_regenerate_image: Skip image regeneration flag.
716704
encrypt: Encryption flag.
@@ -773,9 +761,6 @@ def create(
773761
'qemu_prog_path': qemu_prog_path,
774762
'qemu_cli_args': qemu_cli_args,
775763
'qemu_extra_args': qemu_extra_args,
776-
'wokwi_cli_path': wokwi_cli_path,
777-
'wokwi_timeout': wokwi_timeout,
778-
'wokwi_scenario': wokwi_scenario,
779764
'wokwi_diagram': wokwi_diagram,
780765
'skip_regenerate_image': skip_regenerate_image,
781766
'encrypt': encrypt,

pytest-embedded/pytest_embedded/plugin.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,6 @@ def pytest_addoption(parser):
297297
)
298298

299299
wokwi_group = parser.getgroup('embedded-wokwi')
300-
wokwi_group.addoption(
301-
'--wokwi-cli-path',
302-
help='Path to the wokwi-cli program (Default: "wokwi-cli")',
303-
)
304-
wokwi_group.addoption(
305-
'--wokwi-timeout',
306-
default=86400000,
307-
type=_gte_one_int,
308-
help='Simulation timeout in milliseconds (Default: 86400000)',
309-
)
310-
wokwi_group.addoption(
311-
'--wokwi-scenario',
312-
help='Path to the wokwi scenario file (Default: None)',
313-
)
314300
wokwi_group.addoption(
315301
'--wokwi-diagram',
316302
help='Path to the wokwi diagram file (Default: None)',
@@ -995,27 +981,6 @@ def keyfile(request: FixtureRequest) -> t.Optional[str]:
995981
#########
996982
# Wokwi #
997983
#########
998-
@pytest.fixture
999-
@multi_dut_argument
1000-
def wokwi_cli_path(request: FixtureRequest) -> t.Optional[str]:
1001-
"""Enable parametrization for the same cli option"""
1002-
return _request_param_or_config_option_or_default(request, 'wokwi_cli_path', None)
1003-
1004-
1005-
@pytest.fixture
1006-
@multi_dut_argument
1007-
def wokwi_timeout(request: FixtureRequest) -> t.Optional[str]:
1008-
"""Enable parametrization for the same cli option"""
1009-
return _request_param_or_config_option_or_default(request, 'wokwi_timeout', None)
1010-
1011-
1012-
@pytest.fixture
1013-
@multi_dut_argument
1014-
def wokwi_scenario(request: FixtureRequest) -> t.Optional[str]:
1015-
"""Enable parametrization for the same cli option"""
1016-
return _request_param_or_config_option_or_default(request, 'wokwi_scenario', None)
1017-
1018-
1019984
@pytest.fixture
1020985
@multi_dut_argument
1021986
def wokwi_diagram(request: FixtureRequest) -> t.Optional[str]:
@@ -1079,9 +1044,6 @@ def parametrize_fixtures(
10791044
qemu_prog_path,
10801045
qemu_cli_args,
10811046
qemu_extra_args,
1082-
wokwi_cli_path,
1083-
wokwi_timeout,
1084-
wokwi_scenario,
10851047
wokwi_diagram,
10861048
skip_regenerate_image,
10871049
encrypt,

0 commit comments

Comments
 (0)