From 8fd8766167392f1cda6826d95b32653ebdd7ef1e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 21 Aug 2026 09:35:53 -0500 Subject: [PATCH] Sandbox ESPHOME_ARDUINO8266_PREFIX in the writer test isolation fixture The autouse fixture pinned the idf and sdk-nrf prefixes but not the new arduino8266 one, so running the suite with that env var exported deleted the pointed-to install. Also adds the clean_all removal test the other two native installs already have. --- tests/unit_tests/test_writer.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/test_writer.py b/tests/unit_tests/test_writer.py index 46e60ebd8e..6c05fc330b 100644 --- a/tests/unit_tests/test_writer.py +++ b/tests/unit_tests/test_writer.py @@ -68,7 +68,8 @@ def _isolate_platformio_paths(tmp_path_factory: pytest.TempPathFactory) -> Any: test_clean_all_partial_exists) install their own inner patch which stacks on top of this one and wins for the duration of their block. - Also pin ``ESPHOME_ESP_IDF_PREFIX`` and ``ESPHOME_SDK_NRF_PREFIX`` to + Also pin ``ESPHOME_ESP_IDF_PREFIX``, ``ESPHOME_SDK_NRF_PREFIX`` and + ``ESPHOME_ARDUINO8266_PREFIX`` to nonexistent tmp dirs, and patch ``platformdirs.user_cache_dir``, for the same reason: ``clean_all`` removes the machine-global toolchain installs and their default cache root, which otherwise resolve to the real @@ -77,6 +78,7 @@ def _isolate_platformio_paths(tmp_path_factory: pytest.TempPathFactory) -> Any: pio_root = tmp_path_factory.mktemp("isolated_pio") / "nonexistent" idf_root = tmp_path_factory.mktemp("isolated_idf") / "nonexistent" sdk_nrf_root = tmp_path_factory.mktemp("isolated_sdk_nrf") / "nonexistent" + arduino8266_root = tmp_path_factory.mktemp("isolated_arduino8266") / "nonexistent" cache_root = tmp_path_factory.mktemp("isolated_cache") / "nonexistent" mock_cfg = MagicMock() mock_cfg.get.side_effect = lambda section, option: ( @@ -92,6 +94,7 @@ def _isolate_platformio_paths(tmp_path_factory: pytest.TempPathFactory) -> Any: { "ESPHOME_ESP_IDF_PREFIX": str(idf_root), "ESPHOME_SDK_NRF_PREFIX": str(sdk_nrf_root), + "ESPHOME_ARDUINO8266_PREFIX": str(arduino8266_root), }, ), patch("platformdirs.user_cache_dir", return_value=str(cache_root)), @@ -1033,6 +1036,30 @@ def test_clean_all_removes_global_idf_install( assert str(idf_install.resolve()) in caplog.text +@patch("esphome.writer.CORE") +def test_clean_all_removes_global_arduino8266_install( + mock_core: MagicMock, + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, + caplog: pytest.LogCaptureFixture, +) -> None: + """clean_all removes the machine-global native arduino8266 install dir.""" + arduino8266_install = tmp_path / "arduino8266_install" + (arduino8266_install / "frameworks").mkdir(parents=True) + monkeypatch.setenv("ESPHOME_ARDUINO8266_PREFIX", str(arduino8266_install)) + + config_dir = tmp_path / "config" + config_dir.mkdir() + + from esphome.writer import clean_all + + with caplog.at_level("INFO"): + clean_all([str(config_dir)]) + + assert not arduino8266_install.exists() + assert str(arduino8266_install.resolve()) in caplog.text + + @patch("esphome.writer.CORE") def test_clean_all_removes_global_sdk_nrf_install( mock_core: MagicMock,