From a8c614442d09c366093785adf8b6975a01cd447d Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Thu, 11 Jul 2024 15:14:24 +0200 Subject: [PATCH 1/2] Add a autouse fixture to skip unsupported devices --- CHANGELOG.md | 5 +++++ src/ragger/conftest/base_conftest.py | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c678014f..d62e8b77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.24.0] - 2024-09-24 + +### Added +- conftest: Added a autouse fixture to skip unsupported devices + ## [1.23.0] - 2024-07-25 ### Changed diff --git a/src/ragger/conftest/base_conftest.py b/src/ragger/conftest/base_conftest.py index a61aa6e6..6c7c87d1 100644 --- a/src/ragger/conftest/base_conftest.py +++ b/src/ragger/conftest/base_conftest.py @@ -73,6 +73,19 @@ def root_pytest_dir(request) -> Path: return Path(request.config.rootpath).resolve() +@pytest.fixture(scope="session") +def supported_devices(root_pytest_dir: Path) -> List[str]: + project_root_dir = find_project_root_dir(root_pytest_dir) + manifest = Manifest.from_path(project_root_dir / "ledger_app.toml") + return ["nanosp" if d == "nanos+" else d for d in manifest.app.devices.json] + + +@pytest.fixture(scope="session") +def skip_tests_for_unsupported_devices(supported_devices: List[str], firmware: Firmware): + if firmware.name not in supported_devices: + pytest.skip(f"Device {firmware.name} is not supported according to the manifest") + + @pytest.fixture(autouse="session") def default_screenshot_path(root_pytest_dir: Path) -> Path: # Alias reflecting the use case to avoid exposing internal helper fixtures @@ -213,9 +226,11 @@ def create_backend(root_pytest_dir: Path, backend_name: str, firmware: Firmware, # Backend scope can be configured by the user +# fixture skip_tests_for_unsupported_devices is a dependency because we want to skip the test +# before trying to find the binary @pytest.fixture(scope=conf.OPTIONAL.BACKEND_SCOPE) -def backend(root_pytest_dir: Path, backend_name: str, firmware: Firmware, display: bool, - log_apdu_file: Optional[Path], cli_user_seed: str, +def backend(skip_tests_for_unsupported_devices, root_pytest_dir: Path, backend_name: str, + firmware: Firmware, display: bool, log_apdu_file: Optional[Path], cli_user_seed: str, additional_speculos_arguments: List[str]) -> Generator[BackendInterface, None, None]: with create_backend(root_pytest_dir, backend_name, firmware, display, log_apdu_file, cli_user_seed, additional_speculos_arguments) as b: From 1895125c1bc3d1784663052d1522e573a0b481a7 Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Tue, 24 Sep 2024 11:28:37 +0200 Subject: [PATCH 2/2] Add all_eink device option --- CHANGELOG.md | 1 + src/ragger/conftest/base_conftest.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d62e8b77..3eb4c1a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.24.0] - 2024-09-24 ### Added +- conftest: Added a all_eink device option to target Stax and Flex - conftest: Added a autouse fixture to skip unsupported devices ## [1.23.0] - 2024-07-25 diff --git a/src/ragger/conftest/base_conftest.py b/src/ragger/conftest/base_conftest.py index 6c7c87d1..004813b3 100644 --- a/src/ragger/conftest/base_conftest.py +++ b/src/ragger/conftest/base_conftest.py @@ -14,7 +14,7 @@ BACKENDS = ["speculos", "ledgercomm", "ledgerwallet"] -DEVICES = ["nanos", "nanox", "nanosp", "stax", "flex", "all", "all_nano"] +DEVICES = ["nanos", "nanox", "nanosp", "stax", "flex", "all", "all_nano", "all_eink"] FIRMWARES = [ Firmware.NANOS, @@ -130,7 +130,9 @@ def pytest_generate_tests(metafunc): # Enable firmware for requested devices for fw in FIRMWARES: - if device == fw.name or device == "all" or (device == "all_nano" and fw.is_nano): + if device == fw.name or device == "all" or (device == "all_nano" + and fw.is_nano) or (device == "all_eink" + and not fw.is_nano): fw_list.append(fw) ids.append(fw.name)