diff --git a/CHANGELOG.md b/CHANGELOG.md index 053f3186..fa257744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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.27.0] - 2025-02-21 + +### Added + +- Added support for different test setup + ## [1.26.0] - 2025-02-06 ### Added diff --git a/src/ragger/conftest/base_conftest.py b/src/ragger/conftest/base_conftest.py index 004813b3..a94078da 100644 --- a/src/ragger/conftest/base_conftest.py +++ b/src/ragger/conftest/base_conftest.py @@ -40,6 +40,11 @@ def pytest_addoption(parser): "ones. Will only work with 'speculos' as the backend") parser.addoption("--log_apdu_file", action="store", default=None, help="Log the APDU in a file") parser.addoption("--seed", action="store", default=None, help="Set a custom seed") + parser.addoption("--setup", + action="store", + default="default", + help="Specify the setup fixture (e.g., 'prod_build')", + choices=conf.OPTIONAL.ALLOWED_SETUPS + ["default"]) @pytest.fixture(scope="session") @@ -275,12 +280,36 @@ def use_only_on_backend(request, backend_name): pytest.skip(f'skipped on this backend: "{current_backend}"') +# This fixture looks for the 'needs_setup' marker. Example: +# @pytest.mark.needs_setup('prod_build') +@pytest.fixture(scope="function", autouse=True) +def skip_needs_setup(request): + if request.node.get_closest_marker('needs_setup'): + needed_setup = request.node.get_closest_marker('needs_setup').args[0] + else: + needed_setup = "default" + current_setup = request.config.getoption("--setup") + if needed_setup != current_setup: + pytest.skip(f"Skip test requiring setup {needed_setup} as current setup is {current_setup}") + + def pytest_configure(config): config.addinivalue_line( "markers", "use_on_backend(backend): skip test if not on the specified backend", ) + # fixture with parameter, use with the following syntax + # # @pytest.mark.needs_setup('prod_build') + # if not decorated, defaults to + # # @pytest.mark.needs_setup('default') + # will apply a skip filter against the "--setup " command line argument + # Update configuration.OPTIONAL.ALLOWED_SETUPS when adding new setups to allow the command line to accept them + config.addinivalue_line( + "markers", + "needs_setup(setup_name): skip test if not on the specified setup", + ) + def log_full_conf(): logger = get_default_logger() diff --git a/src/ragger/conftest/configuration.py b/src/ragger/conftest/configuration.py index 45f1d309..2aebc3d5 100644 --- a/src/ragger/conftest/configuration.py +++ b/src/ragger/conftest/configuration.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Optional +from typing import Optional, List @dataclass @@ -10,6 +10,7 @@ class OptionalOptions: SIDELOADED_APPS_DIR: str BACKEND_SCOPE: str CUSTOM_SEED: str + ALLOWED_SETUPS: List[str] OPTIONAL = OptionalOptions( @@ -48,4 +49,15 @@ class OptionalOptions: # This would result in speculos being launched with --seed # If a seed is provided through the "--seed" pytest command line option, it will override this one. CUSTOM_SEED=str(), + + # Use this parameter if you want ragger to handle running different test suites depending on setup + # Useful when some tests need certain build options and other tests need other build options, or a + # different Speculos command line + # Adding a setup will allow you to decorate your tests with it using the following syntax + # @pytest.mark.needs_setup('') + # And run marked tests and only them using the --setup + # + # "default" setup is always allowed, all tests without explicit decoration depend on default + # and the --setup option defaults to "default" + ALLOWED_SETUPS=["default"], )