pytest-embedded 2.9.3__tar.gz → 2.10.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-embedded
3
- Version: 2.9.3
3
+ Version: 2.10.0
4
4
  Summary: A pytest plugin that designed for embedded testing.
5
5
  Author-email: Fu Hanxi <fuhanxi@espressif.com>
6
6
  Requires-Python: >=3.10
@@ -30,5 +30,32 @@ Project-URL: repository, https://github.com/espressif/pytest-embedded
30
30
 
31
31
  ### pytest-embedded
32
32
 
33
- A pytest plugin for embedded systems. Could activate different services for extra functionalities.
33
+ The core plugin for the `pytest-embedded` framework. Designed for embedded testing across multiple targets and environments.
34
+
35
+ #### Key Features
36
+
37
+ - **Core Fixtures**: Provides essential fixtures including `dut`, `app`, `msg_queue`, `pexpect_proc`, and `redirect`.
38
+ - **String & Regex Matching**: Integrates `pexpect` for powerful output parsing with `dut.expect()` and `dut.expect_exact()`.
39
+ - **Multi-DUT Orchestration**: Test multi-device topologies (such as master-slave or mesh networks) using `--count`.
40
+ - **Flexible Parametrization**: Easily parametrize apps, targets, and services using `pytest` markers.
41
+ - **Unified Test Reports**: Parse and merge embedded Unity test results into JUnit XML reports.
42
+
43
+ #### Quickstart
44
+
45
+ ```python
46
+ from pytest_embedded import Dut
47
+
48
+
49
+ def test_basic_expect(redirect, dut: Dut):
50
+ with redirect():
51
+ print('Ready to test!')
52
+
53
+ dut.expect('Ready to test!')
54
+ ```
55
+
56
+ Run the test:
57
+
58
+ ```shell
59
+ pytest test_basic.py -s
60
+ ```
34
61
 
@@ -0,0 +1,30 @@
1
+ ### pytest-embedded
2
+
3
+ The core plugin for the `pytest-embedded` framework. Designed for embedded testing across multiple targets and environments.
4
+
5
+ #### Key Features
6
+
7
+ - **Core Fixtures**: Provides essential fixtures including `dut`, `app`, `msg_queue`, `pexpect_proc`, and `redirect`.
8
+ - **String & Regex Matching**: Integrates `pexpect` for powerful output parsing with `dut.expect()` and `dut.expect_exact()`.
9
+ - **Multi-DUT Orchestration**: Test multi-device topologies (such as master-slave or mesh networks) using `--count`.
10
+ - **Flexible Parametrization**: Easily parametrize apps, targets, and services using `pytest` markers.
11
+ - **Unified Test Reports**: Parse and merge embedded Unity test results into JUnit XML reports.
12
+
13
+ #### Quickstart
14
+
15
+ ```python
16
+ from pytest_embedded import Dut
17
+
18
+
19
+ def test_basic_expect(redirect, dut: Dut):
20
+ with redirect():
21
+ print('Ready to test!')
22
+
23
+ dut.expect('Ready to test!')
24
+ ```
25
+
26
+ Run the test:
27
+
28
+ ```shell
29
+ pytest test_basic.py -s
30
+ ```
@@ -6,4 +6,4 @@ from .dut_factory import DutFactory
6
6
 
7
7
  __all__ = ['App', 'Dut', 'DutFactory']
8
8
 
9
- __version__ = '2.9.3'
9
+ __version__ = '2.10.0'
@@ -13,7 +13,7 @@ from collections import defaultdict
13
13
  from pathlib import Path
14
14
 
15
15
  if t.TYPE_CHECKING:
16
- from pytest_embedded_espemu import EspEmu
16
+ from pytest_embedded_espemu import EspEmu, EspEmuSerial
17
17
  from pytest_embedded_idf import LinuxSerial
18
18
  from pytest_embedded_idf.dut import IdfDut
19
19
  from pytest_embedded_jtag import Gdb, OpenOcd
@@ -162,6 +162,7 @@ def _fixture_classes_and_options_fn(
162
162
  espemu_prog_path,
163
163
  espemu_cli_args,
164
164
  espemu_extra_args,
165
+ espemu_efuse_path,
165
166
  wokwi_diagram,
166
167
  wokwi_usb_serial_jtag,
167
168
  skip_regenerate_image,
@@ -180,6 +181,15 @@ def _fixture_classes_and_options_fn(
180
181
  mixins: dict[str, list[type]] = defaultdict(list)
181
182
  kwargs: dict[str, dict[str, t.Any]] = defaultdict(dict)
182
183
 
184
+ # The emulator and its serial are two fixtures talking over one control
185
+ # channel, so the port is settled here, before either exists, and each is
186
+ # handed it.
187
+ espemu_control_port = None
188
+ if 'espemu' in _services:
189
+ from pytest_embedded_espemu import EspEmu
190
+
191
+ espemu_control_port = EspEmu.pick_control_port(espemu_prog_path)
192
+
183
193
  for fixture in FIXTURES_SERVICES.keys():
184
194
  if fixture == 'app':
185
195
  kwargs['app'] = {'app_path': app_path, 'build_dir': build_dir}
@@ -210,6 +220,8 @@ def _fixture_classes_and_options_fn(
210
220
  'part_tool': part_tool,
211
221
  'espemu_image_path': espemu_image_path,
212
222
  'skip_regenerate_image': skip_regenerate_image,
223
+ 'encrypt': encrypt,
224
+ 'keyfile': keyfile,
213
225
  }
214
226
  )
215
227
  else:
@@ -289,6 +301,14 @@ def _fixture_classes_and_options_fn(
289
301
  from pytest_embedded_serial_esp import EspSerial
290
302
 
291
303
  classes[fixture] = EspSerial
304
+ elif 'espemu' in _services:
305
+ from pytest_embedded_espemu import EspEmuSerial
306
+
307
+ classes[fixture] = EspEmuSerial
308
+ kwargs[fixture] = {
309
+ 'control_port': espemu_control_port,
310
+ 'app': None,
311
+ }
292
312
  elif 'serial' in _services or 'jtag' in _services:
293
313
  from pytest_embedded_serial.serial import Serial
294
314
 
@@ -336,8 +356,14 @@ def _fixture_classes_and_options_fn(
336
356
  kwargs[fixture] = {
337
357
  'msg_queue': msg_queue,
338
358
  'qemu_image_path': qemu_image_path
339
- or os.path.join(
340
- app_path or '', build_dir or 'build', ENCRYPTED_IMAGE_FN if encrypt else DEFAULT_IMAGE_FN
359
+ or (
360
+ None
361
+ if 'arduino' in _services
362
+ else os.path.join(
363
+ app_path or '',
364
+ build_dir or 'build',
365
+ ENCRYPTED_IMAGE_FN if encrypt else DEFAULT_IMAGE_FN,
366
+ )
341
367
  ),
342
368
  'qemu_prog_path': qemu_prog_path,
343
369
  'qemu_cli_args': qemu_cli_args,
@@ -351,6 +377,7 @@ def _fixture_classes_and_options_fn(
351
377
  if 'espemu' in _services:
352
378
  from pytest_embedded_espemu import (
353
379
  DEFAULT_IMAGE_FN,
380
+ ENCRYPTED_IMAGE_FN,
354
381
  EspEmu,
355
382
  )
356
383
 
@@ -358,10 +385,14 @@ def _fixture_classes_and_options_fn(
358
385
  kwargs[fixture] = {
359
386
  'msg_queue': msg_queue,
360
387
  'espemu_image_path': espemu_image_path
361
- or os.path.join(app_path or '', build_dir or 'build', DEFAULT_IMAGE_FN),
388
+ or os.path.join(
389
+ app_path or '', build_dir or 'build', ENCRYPTED_IMAGE_FN if encrypt else DEFAULT_IMAGE_FN
390
+ ),
362
391
  'espemu_prog_path': espemu_prog_path,
363
392
  'espemu_cli_args': espemu_cli_args,
364
393
  'espemu_extra_args': espemu_extra_args,
394
+ 'espemu_efuse_path': espemu_efuse_path,
395
+ 'espemu_control_port': espemu_control_port,
365
396
  'app': None,
366
397
  'meta': _meta,
367
398
  }
@@ -423,6 +454,7 @@ def _fixture_classes_and_options_fn(
423
454
  kwargs[fixture].update(
424
455
  {
425
456
  'espemu': None,
457
+ 'serial': None,
426
458
  }
427
459
  )
428
460
  elif 'qemu' in _services:
@@ -510,7 +542,7 @@ def app_fn(_fixture_classes_and_options: ClassCliOptions) -> App:
510
542
  return cls(**_drop_none_kwargs(kwargs))
511
543
 
512
544
 
513
- def serial_gn(_fixture_classes_and_options, msg_queue, app) -> t.Union['Serial', 'LinuxSerial'] | None:
545
+ def serial_gn(_fixture_classes_and_options, msg_queue, app) -> t.Union['Serial', 'LinuxSerial'] | 'EspEmuSerial' | None:
514
546
  if hasattr(app, 'target') and app.target == 'linux':
515
547
  from pytest_embedded_idf import LinuxSerial
516
548
 
@@ -764,6 +796,7 @@ class DutFactory:
764
796
  espemu_prog_path: str | None = None,
765
797
  espemu_cli_args: str | None = None,
766
798
  espemu_extra_args: str | None = None,
799
+ espemu_efuse_path: str | None = None,
767
800
  wokwi_diagram: str | None = None,
768
801
  wokwi_usb_serial_jtag: bool | None = None,
769
802
  skip_regenerate_image: bool | None = None,
@@ -816,6 +849,7 @@ class DutFactory:
816
849
  espemu_prog_path: esp-emu program path.
817
850
  espemu_cli_args: esp-emu CLI arguments.
818
851
  espemu_extra_args: Additional esp-emu arguments.
852
+ espemu_efuse_path: esp-emu eFuse image path.
819
853
  wokwi_diagram: Wokwi diagram path.
820
854
  wokwi_usb_serial_jtag: Use USB Serial JTAG instead of UART for Wokwi serial communication.
821
855
  skip_regenerate_image: Skip image regeneration flag.
@@ -892,6 +926,7 @@ class DutFactory:
892
926
  'espemu_prog_path': espemu_prog_path,
893
927
  'espemu_cli_args': espemu_cli_args,
894
928
  'espemu_extra_args': espemu_extra_args,
929
+ 'espemu_efuse_path': espemu_efuse_path,
895
930
  'wokwi_diagram': wokwi_diagram,
896
931
  'wokwi_usb_serial_jtag': wokwi_usb_serial_jtag,
897
932
  'skip_regenerate_image': skip_regenerate_image,
@@ -233,7 +233,7 @@ def pytest_addoption(parser: pytest.Parser):
233
233
  idf_group.addoption(
234
234
  '--part-tool',
235
235
  help='Partition tool path, used for parsing partition table. '
236
- '(Default: "$IDF_PATH/components/partition_table/gen_esp32part.py"',
236
+ '(Default: "$IDF_PATH/components/partition_table/gen_esp32part.py")',
237
237
  )
238
238
  idf_group.addoption(
239
239
  '--confirm-target-elf-sha256',
@@ -259,7 +259,7 @@ def pytest_addoption(parser: pytest.Parser):
259
259
  jtag_group.addoption('--gdb-prog-path', help='GDB program path. (Default: "xtensa-esp32-elf-gdb")')
260
260
  jtag_group.addoption(
261
261
  '--gdb-cli-args',
262
- help='GDB cli arguments. (Default: "--quiet"',
262
+ help='GDB cli arguments. (Default: "--quiet")',
263
263
  )
264
264
  jtag_group.addoption(
265
265
  '--no-gdb',
@@ -291,7 +291,7 @@ def pytest_addoption(parser: pytest.Parser):
291
291
  )
292
292
  qemu_group.addoption(
293
293
  '--qemu-efuse-path',
294
- help='This option makes it possible to use efuse in QEMU when it is set up.',
294
+ help='Path to an eFuse file for QEMU simulation. (Default: None)',
295
295
  )
296
296
  qemu_group.addoption(
297
297
  '--skip-regenerate-image',
@@ -300,7 +300,7 @@ def pytest_addoption(parser: pytest.Parser):
300
300
  )
301
301
  qemu_group.addoption(
302
302
  '--encrypt',
303
- help='y/yes/true for True and n/no/false for False. Set to True for pre-encryption workflow (Default: False)',
303
+ help='y/yes/true for True and n/no/false for False. Set to True for pre-encryption workflow. (Default: False)',
304
304
  )
305
305
  qemu_group.addoption(
306
306
  '--keyfile',
@@ -320,6 +320,11 @@ def pytest_addoption(parser: pytest.Parser):
320
320
  '--espemu-cli-args',
321
321
  help='esp-emu cli default arguments. (Default: None)',
322
322
  )
323
+ espemu_group.addoption(
324
+ '--espemu-efuse-path',
325
+ help='esp-emu eFuse image path. The emulator reads it at start and writes it back on exit. '
326
+ 'A blank image is created when the file does not exist. (Default: None)',
327
+ )
323
328
  espemu_group.addoption(
324
329
  '--espemu-extra-args',
325
330
  help='esp-emu cli extra arguments, will append to the argument list. (Default: None)',
@@ -328,7 +333,7 @@ def pytest_addoption(parser: pytest.Parser):
328
333
  wokwi_group = parser.getgroup('embedded-wokwi')
329
334
  wokwi_group.addoption(
330
335
  '--wokwi-diagram',
331
- help='Path to the wokwi diagram file (Default: None)',
336
+ help='Path to the wokwi diagram file. (Default: None)',
332
337
  )
333
338
  wokwi_group.addoption(
334
339
  '--wokwi-usb-serial-jtag',
@@ -422,10 +427,8 @@ def parse_multi_dut_args(count: int, s: str) -> t.Any | tuple[t.Any]:
422
427
  return tuple(_str_bool(item) for item in res)
423
428
 
424
429
 
425
- def multi_dut_argument(func) -> t.Callable[..., str | None | tuple[str | None]]:
426
- """
427
- Used for parse the multi-dut argument according to the `count` amount.
428
- """
430
+ def multi_dut_argument(func) -> t.Callable[..., str | tuple[str | None, ...] | None]:
431
+ """Decorator to parse the multi-dut argument based on the `count` parameter."""
429
432
 
430
433
  @functools.wraps(func)
431
434
  def wrapper(*args, **kwargs):
@@ -1115,6 +1118,13 @@ def espemu_cli_args(request: FixtureRequest) -> str | None:
1115
1118
  return _request_param_or_config_option_or_default(request, 'espemu_cli_args', None)
1116
1119
 
1117
1120
 
1121
+ @pytest.fixture
1122
+ @multi_dut_argument
1123
+ def espemu_efuse_path(request: FixtureRequest) -> str | None:
1124
+ """Enable parametrization for the same cli option"""
1125
+ return _request_param_or_config_option_or_default(request, 'espemu_efuse_path', None)
1126
+
1127
+
1118
1128
  @pytest.fixture
1119
1129
  @multi_dut_argument
1120
1130
  def espemu_extra_args(request: FixtureRequest) -> str | None:
@@ -1222,6 +1232,7 @@ def parametrize_fixtures(
1222
1232
  espemu_prog_path,
1223
1233
  espemu_cli_args,
1224
1234
  espemu_extra_args,
1235
+ espemu_efuse_path,
1225
1236
  wokwi_diagram,
1226
1237
  wokwi_usb_serial_jtag,
1227
1238
  skip_regenerate_image,
@@ -1477,14 +1488,13 @@ class PytestEmbedded:
1477
1488
  skip_marker = item.get_closest_marker('skip_if_soc')
1478
1489
  if not skip_marker:
1479
1490
  continue
1480
- if 'idf' not in map(str.strip, config.getoption('embedded_services').split(',')):
1491
+ services = self.get_param(item, 'embedded_services', config.getoption('embedded_services', ''))
1492
+ if 'idf' not in map(str.strip, (services or '').split(',')):
1481
1493
  raise ValueError("'skip_if_soc' marker must be used with the 'idf' embedded service.")
1482
1494
 
1483
1495
  from esp_bool_parser import parse_bool_expr
1484
1496
 
1485
- target = config.getoption('target', None)
1486
- if hasattr(item, 'callspec'):
1487
- target = item.callspec.params.get('target', None)
1497
+ target = self.get_param(item, 'target', config.getoption('target', None))
1488
1498
  if target == 'auto' or not isinstance(target, str):
1489
1499
  warnings.warn(
1490
1500
  f"Ignoring pytest.mark.skip_if_soc for test item '{item.originalname}': "
@@ -35,7 +35,7 @@ def test_services(testdir):
35
35
  ('idf,serial', {'IdfApp', 'Serial', 'SerialDut'}),
36
36
  ('idf,esp', {'IdfApp', 'IdfSerial', 'IdfDut'}),
37
37
  ('idf,qemu', {'QemuApp', 'Qemu', 'QemuDut'}),
38
- ('idf,espemu', {'EspEmuApp', 'EspEmu', 'EspEmuDut'}),
38
+ ('idf,espemu', {'EspEmuApp', 'EspEmu', 'EspEmuSerial', 'EspEmuDut'}),
39
39
  ('arduino,esp', {'ArduinoApp', 'ArduinoSerial', 'SerialDut'}),
40
40
  ],
41
41
  indirect=True
@@ -1,3 +0,0 @@
1
- ### pytest-embedded
2
-
3
- A pytest plugin for embedded systems. Could activate different services for extra functionalities.