From a317a422da4d6c1cde76eada4488dd49c1aa4211 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Mon, 11 Aug 2025 08:30:22 +0200 Subject: [PATCH] feat(test_build_system): add buildv2_skip marker This marker enables the skipping of tests that, for any reason, cannot be executed with the IDF build system version 2. It accepts an optional string argument that explains why the test cannot be run with version 2. If no explanation is provided, a default message is used. This marker is used in the `pytest_collection_modifyitems` hook to skip tests marked with it when the `--buildv2` pytest command line option is used. Signed-off-by: Frantisek Hrbata --- tools/test_build_system/README.md | 18 ++++++++++++++++++ tools/test_build_system/conftest.py | 13 +++++++++++++ tools/test_build_system/pytest.ini | 1 + 3 files changed, 32 insertions(+) diff --git a/tools/test_build_system/README.md b/tools/test_build_system/README.md index 4aff8ac2998..0bdf25cc358 100644 --- a/tools/test_build_system/README.md +++ b/tools/test_build_system/README.md @@ -131,6 +131,24 @@ def test_idf_copy(idf_copy): run_idf_py('build', env=env) ``` +### `buildv2_skip` marker + +This marker enables the skipping of tests that, for any reason, cannot be +executed with the IDF build system version 2. It accepts an optional string +argument that explains why the test cannot be run with version 2. If no +explanation is provided, a default message is used. This marker is used in +the `pytest_collection_modifyitems` hook to skip tests marked with it when the +`--buildv2` pytest command line option is used. For implementation details, +please refer to `conftest.py`. + +```python +@pytest.mark.buildv2_skip +def test_target_guessing() + +@pytest.mark.buildv2_skip('This functionality has not been implemented in cmakev2 yet.') +def test_target_guessing() +``` + ### Build snapshots `get_snapshot(list_of_globs)` function takes a list of glob expressions, finds the files matching these expressions, and returns a `Snapshot` instance. `Snapshot` instances record file names and their modification timestamps. Two `Snapshot` instances can be compared using `assert_same` and `assert_different` methods: diff --git a/tools/test_build_system/conftest.py b/tools/test_build_system/conftest.py index bf2951ab81a..773f718e1eb 100644 --- a/tools/test_build_system/conftest.py +++ b/tools/test_build_system/conftest.py @@ -10,7 +10,10 @@ from pathlib import Path from tempfile import mkdtemp import pytest +from _pytest.config import Config from _pytest.fixtures import FixtureRequest +from _pytest.main import Session +from _pytest.nodes import Item from test_build_system_helpers import EXT_IDF_PATH from test_build_system_helpers import EnvDict from test_build_system_helpers import IdfPyFunc @@ -235,3 +238,13 @@ def idf_py(default_idf_env: EnvDict) -> IdfPyFunc: return run_idf_py(*args, env=default_idf_env, workdir=os.getcwd(), check=check, input_str=input_str) # type: ignore return result + + +def pytest_collection_modifyitems(session: Session, config: Config, items: list[Item]) -> None: + if not config.getoption('--buildv2', False): + return + for item in items: + marker = item.get_closest_marker('buildv2_skip') + if marker: + reason = marker.args[0] if marker.args else 'Skipped as this test is specific to build system v1.' + item.add_marker(pytest.mark.skip(reason=reason)) diff --git a/tools/test_build_system/pytest.ini b/tools/test_build_system/pytest.ini index eeac16e6d7b..0e6a45443be 100644 --- a/tools/test_build_system/pytest.ini +++ b/tools/test_build_system/pytest.ini @@ -21,3 +21,4 @@ markers = idf_copy_with_space: ensures that destination directory where IDF is copied contain space force_temp_work_dir: force temporary folder as the working directory with_idf_components: automatically create/delete components under IDF_PATH + buildv2_skip: mark the test to run only when the --buildv2 command line option is not used