Skip to content

Commit

Permalink
Add a autouse fixture to skip unsupported devices
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Sep 24, 2024
1 parent 08914eb commit 8ecacd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/ragger/conftest/base_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ 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", autouse=True)
def skip_tests_for_unsupported_devices(request, supported_devices: List[str]):
# We could request firmware as a fixture but that would fail on tests of the Speculos interface
# Instead we 'soft-request' firmware and do nothing if it is missing
if 'firmware' in request.fixturenames:
firmware = request.getfixturevalue('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
Expand Down Expand Up @@ -213,9 +230,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:
Expand Down

0 comments on commit 8ecacd4

Please sign in to comment.