pytest-embedded-espemu 2.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Espressif Systems (Shanghai) Co. Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-embedded-espemu
3
+ Version: 2.9.0
4
+ Summary: Make pytest-embedded plugin work with esp-emu.
5
+ Author: Espressif Systems
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Framework :: Pytest
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python
21
+ Classifier: Topic :: Software Development :: Testing
22
+ License-File: LICENSE
23
+ Requires-Dist: pytest-embedded~=2.9.0
24
+ Requires-Dist: pytest-embedded-idf~=2.9.0 ; extra == "idf"
25
+ Project-URL: changelog, https://github.com/espressif/pytest-embedded/blob/main/CHANGELOG.md
26
+ Project-URL: documentation, https://docs.espressif.com/projects/pytest-embedded/en/latest/
27
+ Project-URL: homepage, https://github.com/espressif/pytest-embedded
28
+ Project-URL: repository, https://github.com/espressif/pytest-embedded
29
+ Provides-Extra: idf
30
+
31
+ ### pytest-embedded-espemu
32
+
33
+ pytest-embedded service for running tests on [esp-emu](https://github.com/espressif/esp-emulator), Espressif's lightweight emulator for ESP RISC-V series SoCs, instead of real targets.
34
+
35
+ Supported targets: `esp32c3`, `esp32c6`, `esp32h2`, `esp32p4`, `esp32s31`.
36
+
37
+ #### Usage
38
+
39
+ ```shell
40
+ pytest --embedded-services idf,espemu --target esp32c3
41
+ ```
42
+
43
+ The service builds a merged flash binary from the app's build directory (via `esptool merge-bin`), launches `esp-emu` with UART0 on stdio, and drives it like any other DUT — including the Unity test menu machinery from `pytest-embedded-idf`.
44
+
45
+ Extra CLI options:
46
+
47
+ - `--espemu-image-path`: use an existing merged flash binary instead of generating one
48
+ - `--espemu-prog-path`: path to the `esp-emu` binary (default: `esp-emu` from `PATH`)
49
+ - `--espemu-cli-args` / `--espemu-extra-args`: forwarded to the `esp-emu` command line, e.g. `--espemu-extra-args "--net user,restrict=yes"`
50
+
@@ -0,0 +1,19 @@
1
+ ### pytest-embedded-espemu
2
+
3
+ pytest-embedded service for running tests on [esp-emu](https://github.com/espressif/esp-emulator), Espressif's lightweight emulator for ESP RISC-V series SoCs, instead of real targets.
4
+
5
+ Supported targets: `esp32c3`, `esp32c6`, `esp32h2`, `esp32p4`, `esp32s31`.
6
+
7
+ #### Usage
8
+
9
+ ```shell
10
+ pytest --embedded-services idf,espemu --target esp32c3
11
+ ```
12
+
13
+ The service builds a merged flash binary from the app's build directory (via `esptool merge-bin`), launches `esp-emu` with UART0 on stdio, and drives it like any other DUT — including the Unity test menu machinery from `pytest-embedded-idf`.
14
+
15
+ Extra CLI options:
16
+
17
+ - `--espemu-image-path`: use an existing merged flash binary instead of generating one
18
+ - `--espemu-prog-path`: path to the `esp-emu` binary (default: `esp-emu` from `PATH`)
19
+ - `--espemu-cli-args` / `--espemu-extra-args`: forwarded to the `esp-emu` command line, e.g. `--espemu-extra-args "--net user,restrict=yes"`
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["flit_core >=3.2,<4"]
3
+ build-backend = "flit_core.buildapi"
4
+
5
+ [project]
6
+ name = "pytest-embedded-espemu"
7
+ authors = [
8
+ {name = "Espressif Systems"},
9
+ ]
10
+ readme = "README.md"
11
+ license = {file = "LICENSE"}
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Framework :: Pytest",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Programming Language :: Python",
26
+ "Topic :: Software Development :: Testing",
27
+ ]
28
+ dynamic = ["version", "description"]
29
+ requires-python = ">=3.10"
30
+
31
+ dependencies = [
32
+ "pytest-embedded~=2.9.0",
33
+ ]
34
+
35
+ [project.optional-dependencies]
36
+ idf = [
37
+ "pytest-embedded-idf~=2.9.0",
38
+ ]
39
+
40
+ [project.urls]
41
+ homepage = "https://github.com/espressif/pytest-embedded"
42
+ repository = "https://github.com/espressif/pytest-embedded"
43
+ documentation = "https://docs.espressif.com/projects/pytest-embedded/en/latest/"
44
+ changelog = "https://github.com/espressif/pytest-embedded/blob/main/CHANGELOG.md"
@@ -0,0 +1,31 @@
1
+ """Make pytest-embedded plugin work with esp-emu."""
2
+
3
+ import importlib
4
+
5
+ from pytest_embedded.utils import lazy_load
6
+
7
+ DEFAULT_IMAGE_FN = 'espemu_image.bin'
8
+
9
+ from .dut import EspEmuDut # noqa
10
+ from .espemu import EspEmu # noqa
11
+
12
+ __getattr__ = lazy_load(
13
+ importlib.import_module(__name__),
14
+ {
15
+ 'EspEmu': EspEmu,
16
+ 'EspEmuDut': EspEmuDut,
17
+ },
18
+ {
19
+ 'EspEmuApp': '.app', # requires idf
20
+ },
21
+ )
22
+
23
+
24
+ __all__ = [
25
+ 'DEFAULT_IMAGE_FN',
26
+ 'EspEmu',
27
+ 'EspEmuApp',
28
+ 'EspEmuDut',
29
+ ]
30
+
31
+ __version__ = '2.9.0'
@@ -0,0 +1,67 @@
1
+ import contextlib
2
+ import logging
3
+ import os
4
+ import sys
5
+
6
+ from pytest_embedded.log import MessageQueue, live_print_call
7
+ from pytest_embedded_idf.app import IdfApp
8
+
9
+ from . import DEFAULT_IMAGE_FN
10
+
11
+
12
+ class EspEmuApp(IdfApp):
13
+ """
14
+ esp-emu App class
15
+
16
+ Attributes:
17
+ image_path (str): esp-emu flash-able bin path
18
+ """
19
+
20
+ def __init__(
21
+ self,
22
+ msg_queue: MessageQueue,
23
+ espemu_image_path: str | None = None,
24
+ skip_regenerate_image: bool | None = False,
25
+ **kwargs,
26
+ ):
27
+ self._q = msg_queue
28
+
29
+ super().__init__(**kwargs)
30
+
31
+ self.image_path = espemu_image_path or os.path.join(self.binary_path, DEFAULT_IMAGE_FN)
32
+ self.skip_regenerate_image = skip_regenerate_image
33
+
34
+ self.create_image()
35
+
36
+ def create_image(self) -> None:
37
+ """
38
+ Create the image, if it doesn't exist.
39
+ """
40
+ if os.path.exists(self.image_path) and self.skip_regenerate_image:
41
+ logging.info(f'Using existing image: {self.image_path}')
42
+ return
43
+
44
+ try:
45
+ import esptool # noqa
46
+ except ImportError:
47
+ raise ImportError(
48
+ 'esptool is required for creating esp-emu images. '
49
+ 'Please install esptool with "pip install -U esptool" or use an existing image.'
50
+ )
51
+
52
+ # esp-emu accepts a plain merged flash binary, no flash-size padding needed
53
+ with contextlib.redirect_stdout(self._q):
54
+ live_print_call(
55
+ [
56
+ sys.executable,
57
+ '-m',
58
+ 'esptool',
59
+ '--chip',
60
+ self.target,
61
+ 'merge-bin',
62
+ '-o',
63
+ self.image_path,
64
+ *self.write_flash_args,
65
+ ],
66
+ cwd=self.binary_path,
67
+ )
@@ -0,0 +1,25 @@
1
+ from typing import AnyStr
2
+
3
+ from pytest_embedded.dut import Dut
4
+
5
+ from .espemu import EspEmu
6
+
7
+
8
+ class EspEmuDut(Dut):
9
+ """
10
+ esp-emu dut class
11
+ """
12
+
13
+ def __init__(
14
+ self,
15
+ espemu: EspEmu,
16
+ **kwargs,
17
+ ) -> None:
18
+ self.espemu = espemu
19
+
20
+ super().__init__(**kwargs)
21
+
22
+ self._hard_reset_func = self.espemu._hard_reset
23
+
24
+ def write(self, s: AnyStr) -> None:
25
+ self.espemu.write(s)
@@ -0,0 +1,76 @@
1
+ import shlex
2
+ import typing as t
3
+
4
+ from pytest_embedded.log import DuplicateStdoutPopen
5
+
6
+ if t.TYPE_CHECKING:
7
+ from .app import EspEmuApp
8
+
9
+
10
+ class EspEmu(DuplicateStdoutPopen):
11
+ """
12
+ esp-emu class (https://github.com/espressif/esp-emulator)
13
+
14
+ The emulator runs with UART0 attached to stdio: its output streams
15
+ straight into the pexpect process and `write()` feeds the firmware's
16
+ UART RX via stdin. No sockets are involved.
17
+ """
18
+
19
+ SOURCE = 'ESPEMU'
20
+
21
+ ESPEMU_PROG_PATH = 'esp-emu'
22
+
23
+ SUPPORTED_TARGETS: t.ClassVar[tuple] = ('esp32c3', 'esp32c6', 'esp32h2', 'esp32p4', 'esp32s31')
24
+
25
+ def __init__(
26
+ self,
27
+ espemu_image_path: str | None = None,
28
+ espemu_prog_path: str | None = None,
29
+ espemu_cli_args: str | None = None,
30
+ espemu_extra_args: str | None = None,
31
+ app: t.Optional['EspEmuApp'] = None,
32
+ **kwargs,
33
+ ):
34
+ """
35
+ Args:
36
+ espemu_image_path: image path (merged flash binary)
37
+ espemu_prog_path: esp-emu program path
38
+ espemu_cli_args: esp-emu CLI arguments
39
+ espemu_extra_args: esp-emu CLI extra arguments, will be appended to `espemu_cli_args`
40
+ app: `EspEmuApp` instance, used to detect the target chip
41
+ """
42
+ self.app = app
43
+
44
+ image_path = espemu_image_path
45
+ if not image_path and self.app:
46
+ image_path = self.app.image_path
47
+ if not image_path:
48
+ raise ValueError('Please specify --espemu-image-path or use the espemu service together with idf')
49
+
50
+ target = getattr(self.app, 'target', None)
51
+ if target not in self.SUPPORTED_TARGETS:
52
+ raise ValueError(
53
+ f'esp-emu does not support target {target!r}. Supported targets: {", ".join(self.SUPPORTED_TARGETS)}'
54
+ )
55
+
56
+ espemu_prog_path = espemu_prog_path or self.ESPEMU_PROG_PATH
57
+
58
+ cmd = [
59
+ espemu_prog_path,
60
+ '--chip',
61
+ target,
62
+ '--firmware',
63
+ image_path,
64
+ *shlex.split(espemu_cli_args or ''),
65
+ *shlex.split(espemu_extra_args or ''),
66
+ ]
67
+
68
+ super().__init__(cmd=cmd, **kwargs)
69
+
70
+ def _hard_reset(self):
71
+ """
72
+ esp-emu has no reset API. Raising `NotImplementedError` makes
73
+ `IdfUnityDutMixin` fall back to re-triggering the Unity test menu
74
+ with a newline instead of resetting the target.
75
+ """
76
+ raise NotImplementedError('esp-emu does not support resetting; relaunch the emulator instead')
@@ -0,0 +1,72 @@
1
+ import os
2
+ import shutil
3
+
4
+ import pytest
5
+
6
+ espemu_bin_required = pytest.mark.skipif(
7
+ shutil.which('esp-emu') is None,
8
+ reason='Please make sure esp-emu is installed and on PATH. See https://github.com/espressif/esp-emulator#install',
9
+ )
10
+
11
+
12
+ @espemu_bin_required
13
+ def test_pexpect_by_espemu(testdir):
14
+ testdir.makepyfile("""
15
+ import pexpect
16
+ import pytest
17
+
18
+ def test_pexpect_by_espemu(dut):
19
+ dut.expect('Hello world!')
20
+ dut.expect('Restarting')
21
+ with pytest.raises(pexpect.TIMEOUT):
22
+ dut.expect('foo bar not found', timeout=1)
23
+ """)
24
+
25
+ result = testdir.runpytest(
26
+ '-s',
27
+ '--embedded-services',
28
+ 'idf,espemu',
29
+ '--app-path',
30
+ os.path.join(testdir.tmpdir, 'hello_world_esp32c3'),
31
+ )
32
+
33
+ result.assert_outcomes(passed=1)
34
+
35
+
36
+ @espemu_bin_required
37
+ def test_multi_count_espemu(testdir):
38
+ testdir.makepyfile("""
39
+ def test_multi_count_espemu(dut):
40
+ dut[0].expect('Hello world!')
41
+ dut[1].expect('Restarting')
42
+ """)
43
+
44
+ result = testdir.runpytest(
45
+ '-s',
46
+ '--count',
47
+ 2,
48
+ '--embedded-services',
49
+ 'idf,espemu|idf,espemu',
50
+ '--app-path',
51
+ f'{os.path.join(testdir.tmpdir, "hello_world_esp32c3")}|{os.path.join(testdir.tmpdir, "hello_world_esp32c3")}',
52
+ )
53
+
54
+ result.assert_outcomes(passed=1)
55
+
56
+
57
+ @espemu_bin_required
58
+ def test_unsupported_target_espemu(testdir):
59
+ testdir.makepyfile("""
60
+ def test_unsupported_target_espemu(dut):
61
+ pass
62
+ """)
63
+
64
+ result = testdir.runpytest(
65
+ '-s',
66
+ '--embedded-services',
67
+ 'idf,espemu',
68
+ '--app-path',
69
+ os.path.join(testdir.tmpdir, 'hello_world_esp32'), # xtensa, not emulated
70
+ )
71
+
72
+ result.assert_outcomes(errors=1)