From ccbb415be8b1e9b52b1b5caecd5f1054575b7e36 Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Thu, 15 Aug 2024 11:53:48 +0200 Subject: [PATCH] feat(tools): add pytest mark idf_copy_with_space --- tools/test_build_system/README.md | 2 ++ tools/test_build_system/conftest.py | 4 ++++ tools/test_build_system/pytest.ini | 2 ++ tools/test_build_system/test_kconfig.py | 2 +- tools/test_build_system/test_spaces.py | 12 ++++++------ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/test_build_system/README.md b/tools/test_build_system/README.md index 0563d75ffa..30fa0e7eec 100644 --- a/tools/test_build_system/README.md +++ b/tools/test_build_system/README.md @@ -114,6 +114,8 @@ Note, `default_idf_env` sets up the environment based on the `IDF_PATH` environm Copies IDF from `IDF_PATH` into a new temporary directory. `@pytest.mark.idf_copy('name prefix')` can be used to specify the name prefix of the temporary directory. +The marker `@pytest.mark.idf_copy_with_space` can be used in combination with `idf_copy` fixture to create a temporary directory with a space in the name. + For the duration of the test, `IDF_PATH` environment variable is set to the newly created copy. ```python diff --git a/tools/test_build_system/conftest.py b/tools/test_build_system/conftest.py index 2607f06938..0b8472fccc 100644 --- a/tools/test_build_system/conftest.py +++ b/tools/test_build_system/conftest.py @@ -157,6 +157,10 @@ def test_git_template_app(func_work_dir: Path, request: FixtureRequest) -> typin @pytest.fixture def idf_copy(func_work_dir: Path, request: FixtureRequest) -> typing.Generator[Path, None, None]: copy_to = request.node.name + '_idf' + # allow overriding the destination via pytest.mark.idf_copy_with_space so the destination contain space + mark_with_space = request.node.get_closest_marker('idf_copy_with_space') + if mark_with_space: + copy_to = request.node.name + ' idf' # allow overriding the destination via pytest.mark.idf_copy() mark = request.node.get_closest_marker('idf_copy') diff --git a/tools/test_build_system/pytest.ini b/tools/test_build_system/pytest.ini index 0db692d048..433952425a 100644 --- a/tools/test_build_system/pytest.ini +++ b/tools/test_build_system/pytest.ini @@ -13,7 +13,9 @@ junit_family = xunit1 junit_logging = stdout junit_log_passing_tests = False +## !! When adding new markers, don't forget to update also the tools\test_build_system\README.md !! markers = test_app_copy: specify relative path of the app to copy, and the prefix of the destination directory name idf_copy: specify the prefix of the destination directory where IDF should be copied + 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 diff --git a/tools/test_build_system/test_kconfig.py b/tools/test_build_system/test_kconfig.py index 181533c790..5ed0f33f0c 100644 --- a/tools/test_build_system/test_kconfig.py +++ b/tools/test_build_system/test_kconfig.py @@ -79,7 +79,7 @@ def test_kconfig_deprecated_options(idf_py: IdfPyFunc, test_app_copy: Path) -> N @pytest.mark.usefixtures('idf_copy') -@pytest.mark.idf_copy('test_kconfig_variouos_options') +@pytest.mark.idf_copy('test_kconfig_various_options') def test_kconfig_multiple_and_target_specific_options(idf_py: IdfPyFunc, test_app_copy: Path) -> None: idf_path = Path(os.environ['IDF_PATH']) diff --git a/tools/test_build_system/test_spaces.py b/tools/test_build_system/test_spaces.py index 5a21214997..d4c540179f 100644 --- a/tools/test_build_system/test_spaces.py +++ b/tools/test_build_system/test_spaces.py @@ -21,7 +21,7 @@ def clean_app_dir(app_path: Path) -> None: shutil.rmtree(app_path / 'build', ignore_errors=True) -@pytest.mark.idf_copy('esp idf with spaces') +@pytest.mark.idf_copy_with_space def test_spaces_bundle1(idf_copy: Path) -> None: logging.info('Running test spaces bundle 1') # test spiffsgen @@ -32,7 +32,7 @@ def test_spaces_bundle1(idf_copy: Path) -> None: run_idf_py('-DIDF_TARGET=esp32s2', 'build', workdir=(idf_copy / 'examples' / 'system' / 'ulp' / 'ulp_riscv' / 'gpio')) -@pytest.mark.idf_copy('esp idf with spaces') +@pytest.mark.idf_copy_with_space def test_spaces_bundle2(idf_copy: Path) -> None: logging.info('Running test spaces bundle 2') # test flash_encryption @@ -41,7 +41,7 @@ def test_spaces_bundle2(idf_copy: Path) -> None: run_idf_py('build', workdir=(idf_copy / 'examples' / 'protocols' / 'https_x509_bundle')) -@pytest.mark.idf_copy('esp idf with spaces') +@pytest.mark.idf_copy_with_space def test_spaces_bundle3(idf_copy: Path) -> None: logging.info('Running test spaces bundle 3') secure_boot_app_path = (idf_copy / 'tools' / 'test_apps' / 'security' / 'secure_boot') @@ -67,7 +67,7 @@ def test_spaces_bundle3(idf_copy: Path) -> None: # Dummy parameter with a space in it, used so that the test directory name contains a space pytest.param('test spaces') ]) -@pytest.mark.idf_copy('esp idf with spaces') +@pytest.mark.idf_copy_with_space @pytest.mark.usefixtures('idf_copy') def test_spaces_bundle4(dummy_: str, idf_py: IdfPyFunc, test_app_copy: Path) -> None: logging.info(f'Running test spaces bundle 4 in {test_app_copy}') @@ -83,7 +83,7 @@ def test_spaces_bundle4(dummy_: str, idf_py: IdfPyFunc, test_app_copy: Path) -> @pytest.mark.skipif(sys.platform == 'win32', reason='Unix test') -@pytest.mark.idf_copy('esp idf with spaces') +@pytest.mark.idf_copy_with_space def test_install_export_unix(idf_copy: Path) -> None: logging.info('install and export setup scripts') env = dict(**os.environ) @@ -100,7 +100,7 @@ def test_install_export_unix(idf_copy: Path) -> None: @pytest.mark.skipif(sys.platform != 'win32', reason='Windows test') -@pytest.mark.idf_copy('esp idf with spaces') +@pytest.mark.idf_copy_with_space def test_install_export_win(idf_copy: Path) -> None: logging.info('install and export setup scripts') env = dict(**os.environ)