pytest-embedded 1.3.3__tar.gz → 1.3.5__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.1
2
2
  Name: pytest-embedded
3
- Version: 1.3.3
3
+ Version: 1.3.5
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.7
@@ -5,4 +5,4 @@ from .dut import Dut
5
5
 
6
6
  __all__ = ['App', 'Dut']
7
7
 
8
- __version__ = '1.3.3'
8
+ __version__ = '1.3.5'
@@ -1,11 +1,13 @@
1
1
  import contextlib
2
2
  import datetime
3
+ import dbm
3
4
  import functools
4
5
  import importlib
5
6
  import io
6
7
  import logging
7
8
  import multiprocessing
8
9
  import os
10
+ import shelve
9
11
  import subprocess
10
12
  import sys
11
13
  import tempfile
@@ -102,6 +104,9 @@ def pytest_addoption(parser):
102
104
 
103
105
  # supports parametrization
104
106
  base_group.addoption('--root-logdir', help='set session-based root log dir. (Default: system temp folder)')
107
+ base_group.addoption(
108
+ '--cache-dir', help='set root cache-dir for storing cache files. \n' '(Default: system temp folder)'
109
+ )
105
110
  base_group.addoption(
106
111
  '--embedded-services',
107
112
  default='',
@@ -528,9 +533,32 @@ def session_tempdir(session_root_logdir) -> str:
528
533
 
529
534
 
530
535
  @pytest.fixture(scope='session')
531
- def port_target_cache() -> t.Dict[str, str]:
536
+ def cache_dir(request: FixtureRequest) -> str:
537
+ """Cache dir for pytest-embedded"""
538
+ _cache_root_dir = os.path.realpath(
539
+ _request_param_or_config_option_or_default(request, 'cache_dir', tempfile.gettempdir())
540
+ )
541
+ _cache_work_dir = os.path.join(_cache_root_dir, 'pytest-embedded', 'pytest-embedded-cache')
542
+ os.makedirs(_cache_work_dir, exist_ok=True)
543
+ return _cache_work_dir
544
+
545
+
546
+ @pytest.fixture(scope='session')
547
+ def port_target_cache(cache_dir) -> t.Dict[str, str]:
532
548
  """Session scoped port-target cache, for esp only"""
533
- return {}
549
+ _cache_file_path = os.path.join(cache_dir, 'port_target_cache')
550
+ resp: t.Dict[str, str] = {}
551
+ try:
552
+ with shelve.open(_cache_file_path) as f:
553
+ resp = dict(f)
554
+ except dbm.error:
555
+ os.remove(_cache_file_path)
556
+
557
+ yield resp
558
+
559
+ with shelve.open(_cache_file_path) as f:
560
+ for k, v in resp.items():
561
+ f[k] = v
534
562
 
535
563
 
536
564
  @pytest.fixture(scope='session')
@@ -1298,7 +1326,7 @@ def dut(
1298
1326
  app: App,
1299
1327
  serial: t.Optional[t.Union['Serial', 'LinuxSerial']],
1300
1328
  qemu: t.Optional['Qemu'],
1301
- ) -> Dut:
1329
+ ) -> t.Union[Dut, t.List[Dut]]:
1302
1330
  """
1303
1331
  A device under test (DUT) object that could gather output from various sources and redirect them to the pexpect
1304
1332
  process, and run `expect()` via its pexpect process.
File without changes