Skip to content

Commit

Permalink
feat(wokwi): support for specifying simulation timeout
Browse files Browse the repository at this point in the history
fixes #263
  • Loading branch information
urish committed Feb 11, 2024
1 parent 7498230 commit 04c7c5a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pytest-embedded-wokwi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ Windows PowerShell:
```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
```

If your tests run for longer than 30 seconds, you may have to increase the simulation timeout. For example, to set the timeout to 60 seconds (60000 milliseconds):

```
pytest --embedded-services idf,wokwi --wokwi-timeout=60000
```
6 changes: 5 additions & 1 deletion pytest-embedded-wokwi/pytest_embedded_wokwi/wokwi_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
self,
firmware_resolver: IDFFirmwareResolver,
wokwi_cli_path: t.Optional[str] = None,
wokwi_timeout: t.Optional[int] = None,
app: t.Optional['IdfApp'] = None,
**kwargs,
):
Expand All @@ -52,9 +53,12 @@ def __init__(
self.create_diagram_json()

wokwi_cli = wokwi_cli_path or self.wokwi_cli_executable
cmd = [wokwi_cli, '--interactive', app.app_path]
if (wokwi_timeout is not None) and (wokwi_timeout > 0):
cmd.extend(['--timeout', str(wokwi_timeout)])

super().__init__(
cmd=[wokwi_cli, '--interactive', app.app_path],
cmd=cmd,
**kwargs,
)

Expand Down
15 changes: 15 additions & 0 deletions pytest-embedded/pytest_embedded/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ def pytest_addoption(parser):
'--wokwi-cli-path',
help='Path to the wokwi-cli program (Default: "wokwi-cli")',
)
wokwi_group.addoption(
'--wokwi-timeout',
default=1,
type=_gte_one_int,
help='Simulation timeout in milliseconds (Default: 30000)',
)


###########
Expand Down Expand Up @@ -978,6 +984,13 @@ def wokwi_cli_path(request: FixtureRequest) -> t.Optional[str]:
return _request_param_or_config_option_or_default(request, 'wokwi_cli_path', None)


@pytest.fixture
@multi_dut_argument
def wokwi_timeout(request: FixtureRequest) -> t.Optional[str]:
"""Enable parametrization for the same cli option"""
return _request_param_or_config_option_or_default(request, 'wokwi_timeout', None)


####################
# Private Fixtures #
####################
Expand Down Expand Up @@ -1039,6 +1052,7 @@ def _fixture_classes_and_options(
qemu_cli_args,
qemu_extra_args,
wokwi_cli_path,
wokwi_timeout,
skip_regenerate_image,
encrypt,
keyfile,
Expand Down Expand Up @@ -1215,6 +1229,7 @@ def _fixture_classes_and_options(
kwargs[fixture].update(
{
'wokwi_cli_path': wokwi_cli_path,
'wokwi_timeout': wokwi_timeout,
'msg_queue': msg_queue,
'app': None,
'meta': _meta,
Expand Down

0 comments on commit 04c7c5a

Please sign in to comment.