diff --git a/tools/test_build_system/conftest.py b/tools/test_build_system/conftest.py index fa9e9cb815..4cf7f5e570 100644 --- a/tools/test_build_system/conftest.py +++ b/tools/test_build_system/conftest.py @@ -349,6 +349,24 @@ def pytest_report_header(config: Config) -> str: return 'Testing ESP-IDF CMake-based build system v1' +@pytest.fixture +def clean_root_managed_components(tmp_path: Path) -> typing.Generator[None, None, None]: + """ + Temporarily clear root managed components and restore them after the test. + """ + from idf_component_tools.config import root_managed_components_dir + + root_managed = str(root_managed_components_dir()) + backup = tmp_path / 'root_managed_backup' + if os.path.isdir(root_managed): + shutil.copytree(root_managed, backup) + shutil.rmtree(root_managed) + yield + shutil.rmtree(root_managed, ignore_errors=True) + if backup.is_dir(): + shutil.copytree(str(backup), root_managed) + + @pytest.fixture(autouse=True) def revert_later(request: FixtureRequest) -> typing.Generator[None, None, None]: origin_content_d: dict[str, str] = {} diff --git a/tools/test_build_system/test_component_manager.py b/tools/test_build_system/test_component_manager.py index 247468c2fb..c68131a7b1 100644 --- a/tools/test_build_system/test_component_manager.py +++ b/tools/test_build_system/test_component_manager.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import json import os.path @@ -208,6 +208,10 @@ class TestOptionalDependencyWithKconfig: @pytest.mark.buildv2_skip('Root components (idf_extra_components.yml) not yet supported in cmakev2') @pytest.mark.revert_later(['tools/idf_extra_components.yml']) class TestIdfRootDependency: + @pytest.fixture(autouse=True) + def _clean_root_managed(self, clean_root_managed_components: None) -> None: + pass + def test_basic_build(self, idf_py: IdfPyFunc, test_app_copy: Path) -> None: with open(os.path.join(EXT_IDF_PATH, 'tools', 'idf_extra_components.yml'), 'w') as fw: fw.write( diff --git a/tools/test_build_system/test_components.py b/tools/test_build_system/test_components.py index c5b226a4b3..5f9ec17b5e 100644 --- a/tools/test_build_system/test_components.py +++ b/tools/test_build_system/test_components.py @@ -246,7 +246,9 @@ def test_extra_components_overrides_managed_components(idf_py: IdfPyFunc, test_a @pytest.mark.with_idf_components(['cmp']) -def test_managed_components_overrides_idf_components(idf_py: IdfPyFunc, test_app_copy: Path) -> None: +def test_managed_components_overrides_idf_components( + idf_py: IdfPyFunc, test_app_copy: Path, clean_root_managed_components: None +) -> None: logging.info('Managed components override components defined in IDF_PATH/components') # created idf component 'cmp' in marker idf_path = Path(os.environ['IDF_PATH'])